在CentOS系统上进行SFTP安全加固,可以采取以下几种方法:
禁用root用户的SFTP登录:
/etc/ssh/sshd_config 文件,添加以下内容:Match User root ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no systemctl restart sshd 创建专用的SFTP用户:
sftpuser,并将其主目录设置为 /home/sftpuser:useradd -m -s /sbin/nologin sftpuser passwd sftpuser /etc/ssh/sshd_config 文件,添加以下内容:Match User sftpuser ChrootDirectory /home/sftpuser ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no systemctl restart sshd 配置SELinux:
setenforce 0 /etc/selinux/config 文件,将 SELINUXenforcing 设置为 SELINUXdisabled,然后重启系统。配置防火墙:
firewall-cmd --permanent --add-service=ssh firewall-cmd --permanent --add-service=sftp firewall-cmd --reload 使用chroot限制用户权限:
chrootDirectory,将用户限制在其主目录中,防止用户访问其他系统目录。启用公钥认证:
/etc/ssh/sshd_config 文件,确保以下配置是启用的:PasswordAuthentication no PubkeyAuthentication yes 定期更新和监控:
通过上述措施,可以显著提高CentOS系统上SFTP的安全性。