防止CentOS SSH被暴力破解可以采取以下幾種措施:
禁用 root 用戶登錄:
/etc/ssh/sshd_config
文件,將 PermitRootLogin
設置為 no
:PermitRootLogin no
sudo systemctl restart sshd
更改默認端口:
Port 22099
sudo systemctl restart sshd
使用 SSH 密鑰認證:
sshd_config
文件以禁用密碼認證:PasswordAuthentication no
sudo systemctl restart sshd
使用 Fail2Ban:
sudo yum install fail2ban -y
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
定期更新系統和軟件:
使用防火墻限制訪問:
sudo ufw allow from 192.168.1.0/24 to any port 2222
sudo ufw enable
通過這些措施,可以顯著提高 CentOS 服務器對 SSH 暴力破解攻擊的防御能力。