在CentOS系统中,防止SSH暴力破解的方法有很多种。以下是一些建议:
-
使用防火墙限制访问:
使用iptables或firewalld限制允许访问SSH的IP地址。例如,使用firewalld:sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="允许的IP地址" port protocol="tcp" port="22" accept' sudo firewall-cmd --reload -
更改默认SSH端口:
编辑/etc/ssh/sshd_config文件,将默认的SSH端口(22)更改为其他端口。Port 2222然后重启SSH服务:
sudo systemctl restart sshd -
使用fail2ban限制登录尝试次数:
安装fail2ban:sudo yum install epel-release sudo yum install fail2ban创建一个新的fail2ban配置文件:
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local编辑
/etc/fail2ban/jail.local文件,启用并配置相应的参数:[sshd] enabled = true port = 2222 filter = sshd logpath = /var/log/secure maxretry = 3 bantime = 600启动fail2ban服务:
sudo systemctl start fail2ban sudo systemctl enable fail2ban -
使用公钥认证:
禁用密码登录,改为使用SSH密钥对进行身份验证。编辑/etc/ssh/sshd_config文件:PasswordAuthentication no PubkeyAuthentication yes然后重启SSH服务:
sudo systemctl restart sshd -
使用SSH保持连接活跃:
在/etc/ssh/sshd_config文件中设置以下参数,以防止因网络波动导致的连接中断:ClientAliveInterval 60 ClientAliveCountMax 3然后重启SSH服务:
sudo systemctl restart sshd
通过以上方法,可以有效地防止SSH暴力破解。请根据您的实际需求选择合适的方法进行配置。
版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,请发送邮件至 55@qq.com 举报,一经查实,本站将立刻删除。转转请注明出处:https://www.szhjjp.com/n/1244088.html