防止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 暴力破解攻击的防御能力。