在CentOS系統中,防止SFTP暴力破解可以通過以下幾種方法來實現:
Fail2Ban是一個入侵防御軟件框架,可以監控日志文件并根據配置的規則禁止惡意IP地址。
sudo yum install fail2ban -y
編輯Fail2Ban的配置文件 /etc/fail2ban/jail.local
,添加SFTP相關的配置:
[DEFAULT]
bantime = 600
findtime = 600
maxretry = 3
[sshd]
enabled = true
port = sshd
filter = sshd
logpath = /var/log/secure
maxretry = 3
bantime = 600
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
PAM可以用來限制登錄嘗試次數。
編輯 /etc/pam.d/sshd
文件,添加以下行:
auth required pam_tally2.so onerr=fail deny=3 unlock_time=600
sudo yum install libpam-modules -y
可以使用iptables來限制每個IP地址的連接速率。
sudo iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --set
sudo iptables -A INPUT -p tcp --dport 22 -m state --state NEW -m recent --update --seconds 600 --hitcount 3 -j DROP
sudo service iptables save
使用SSH密鑰認證可以減少暴力破解的可能性。
ssh-keygen -t rsa -b 4096
ssh-copy-id user@server_ip
編輯 /etc/ssh/sshd_config
文件,進行以下修改:
PermitRootLogin no
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM yes
sudo systemctl restart sshd
通過以上方法,可以有效地防止SFTP暴力破解,提高系統的安全性。