防止SFTP暴力破解可从以下方面配置:
sudo apt-get install fail2ban
(Debian)或 sudo yum install fail2ban
(CentOS)。/etc/fail2ban/jail.local
,设置 maxretry
(最大尝试次数)、bantime
(封禁时间)等参数。ssh-keygen -t rsa -b 4096
,将公钥复制到服务器 ~/.ssh/authorized_keys
。/etc/ssh/sshd_config
中设置 PasswordAuthentication no
、PubkeyAuthentication yes
。/etc/pam.d/sshd
,添加 auth required pam_tally2.so deny=3 unlock_time=600
。sshd_config
中设置 MaxAuthTries 3
。iptables
或 ufw
设置规则,例如限制60秒内超过3次连接则丢弃。PermitRootLogin no
。以上措施可组合使用,显著提升SFTP安全性。