登录
首页 >  文章 >  linux

DebianSFTP设置IP白名单攻略

时间:2025-05-27 17:36:19 144浏览 收藏

在Debian系统中,通过编辑OpenSSH服务器的sshd_config文件,可以设置SFTP的IP白名单。首先,打开/etc/ssh/sshd_config文件,使用Match指令添加特定IP地址或地址范围,如192.168.1.100或192.168.1.0/24,并确保配置了SFTP子系统。最后,保存更改并重启SSH服务,验证防火墙设置,以确保只有指定IP能通过SFTP连接到服务器。

Debian SFTP配置中如何设置IP白名单

在Debian系统中,使用OpenSSH服务器进行SFTP连接时,可以通过配置sshd_config文件来设置IP白名单。以下是详细步骤:

  1. 打开SSH配置文件: 首先,你需要编辑SSH服务器的配置文件/etc/ssh/sshd_config。你可以使用任何文本编辑器,例如nano或vim。

    sudo nano /etc/ssh/sshd_config
    
  2. 添加IP白名单: 在sshd_config文件中,你可以使用Match指令来指定特定的IP地址或IP地址范围。例如,如果你想允许来自特定IP地址的连接,可以添加如下内容:

    Match Address 192.168.1.100
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp
    

    如果你想允许一个IP地址范围,可以使用CIDR表示法:

    Match Address 192.168.1.0/24
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp
    

    如果你想允许多个IP地址或范围,可以多次使用Match指令:

    Match Address 192.168.1.100
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp
    
    Match Address 192.168.1.0/24
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp
    
  3. 配置SFTP子系统: 确保你已经配置了SFTP子系统。通常情况下,默认配置已经足够:

    Subsystem sftp internal-sftp
    
  4. 重启SSH服务: 保存并关闭sshd_config文件后,重启SSH服务以使更改生效:

    sudo systemctl restart sshd
    
  5. 验证配置: 确保防火墙允许SSH连接。你可以使用ufw或iptables来配置防火墙规则。例如,使用ufw:

    sudo ufw allow ssh
    sudo ufw reload
    

    或者使用iptables:

    sudo iptables -A INPUT -p tcp --dport 22 -j ACCEPT
    sudo service iptables save
    

通过以上步骤,你就可以在Debian系统中配置SFTP的IP白名单了。这样,只有指定的IP地址或IP地址范围内的设备才能通过SFTP连接到你的服务器。

本篇关于《DebianSFTP设置IP白名单攻略》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于文章的相关知识,请关注golang学习网公众号!

相关阅读
更多>
最新阅读
更多>
课程推荐
更多>