要限制CentOS上的SFTP访问IP,您可以使用防火墙(如firewalld)或SSH配置文件(sshd_config)来实现。下面是两种方法的详细步骤:
方法一:使用firewalld
sudo yum install firewalld
sudo systemctl start firewalld
sudo systemctl enable firewalld
<your_sftp_port>替换为您的SFTP端口号(默认为22):sudo firewall-cmd --permanent --add-port=<your_sftp_port>/tcp
<allowed_ip>替换为您允许访问SFTP的IP地址:sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<allowed_ip>" port protocol="tcp" port="<your_sftp_port>" accept'
sudo firewall-cmd --reload
方法二:使用sshd_config
sudo vi /etc/ssh/sshd_config
<allowed_ip>替换为您允许访问SFTP的IP地址:Match Address <allowed_ip>
ForceCommand internal-sftp
保存并退出文件。
重启SSH服务以应用更改:
sudo systemctl restart sshd
现在,只有指定的IP地址可以访问您的CentOS服务器上的SFTP服务。请注意,这两种方法可以结合使用,以实现更严格的安全策略。