在CentOS系统中,要限制SFTP访问IP,可以通过修改SSH配置文件来实现。以下是具体步骤:
sshd_config文件备份原始配置文件:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.bak
编辑sshd_config文件:
sudo vi /etc/ssh/sshd_config
添加或修改以下配置: 在文件中找到或添加以下行来限制特定IP访问SFTP:
Match Address 192.168.1.100,192.168.1.101
ForceCommand internal-sftp
AllowTcpForwarding no
X11Forwarding no
这里的192.168.1.100和192.168.1.101是你希望允许访问SFTP的IP地址。你可以根据需要添加更多IP地址,用逗号分隔。
保存并退出编辑器:
按Esc键,然后输入:wq并按回车键保存并退出。
重启SSH服务:
sudo systemctl restart sshd
如果你希望通过防火墙来限制IP访问,可以使用firewalld或iptables。
firewalld添加允许的IP地址:
sudo firewall-cmd --permanent --zone=trusted --add-source=192.168.1.100
sudo firewall-cmd --permanent --zone=trusted --add-source=192.168.1.101
重新加载防火墙规则:
sudo firewall-cmd --reload
iptables添加允许的IP地址:
sudo iptables -A INPUT -p tcp --dport 22 -s 192.168.1.100 -j ACCEPT
sudo iptables -A INPUT -p tcp --dport 22 -s 192.168.1.101 -j ACCEPT
保存iptables规则:
sudo service iptables save
重启iptables服务:
sudo systemctl restart iptables
通过以上方法,你可以有效地限制CentOS系统中SFTP服务的访问IP。