防止暴力破解 SSH 的四种方法 LB 2023-10-06 Linux Linux, SSH 1. 修改端口号123$ vim /etc/ssh/sshd_configPort 2222$ systemctl restart sshd 2. 赋予其他用户超级权限123456789# 禁止root登录$ vim /etc/passwdroot:x:0:0:root:/root:/sbin/nologin# 新增超级用户$ useradd -s /bin/bash test$ vim /etc/passwdtest:x:0:0::/home/test:/bin/bash$ passwd test # 设置密码 3. 使用秘钥认证1234# -t: 秘钥类型# -b: 秘钥长度$ ssh-keygen -t rsa -b 4096$ ssh-copy-id root@xx.xx.xx.xx 4. Fail2ban12345678910111213141516171819$ yum install epel-release -y$ yum install fail2ban -y$ vim /etc/fail2ban/jail.conf[ssh-iptables] # 用到的服务enabled = true # 开机自动启用服务filter = sshd # 添加动作是sshdaction = iptables[name=SSH,port=ssh,protocol=tcp]logpath = /var/log/secure # 要监控的站点日志文件# 将5分钟内频繁访问失败3次的IP屏蔽3600秒maxretry = 3 # 设定失败次数findtime = 300 # 一定时间内bantime = 3600 # 屏蔽多长时间$ systemctl restart fail2ban.service$ systemctl enable fail2ban.service# 查看黑名单IP$ iptables -L -n | tail# 移除黑名单$ fail2ban-client set ssh-iptables unbanip 192.168.196.23 参考 https://blog.csdn.net/rhn_111/article/details/129343874