SSH 登录
有时候 SSH 登录后,会有这种提示:
Last failed login: Sun Feb 23 22:33:58 CST 2020 from 104.200.144.166 on ssh:notty
There were 78 failed login attempts since the last successful login.
因此对 SSH 登录做一些安全性的提升。
1. 自动将 SSH 连续登录失败的 IP 地址加入黑名单
参考 《自动将 SSH 连续登录失败的 IP 地址加入黑名单》。
2. 禁止 root 用户远程登录
修改 /etc/ssh/sshd_config
,将 PermitRootLogin
设置为 no
:
PermitRootLogin no
执行 systemctl restart sshd
重启 sshd
服务。
3. 只允许使用 SSH Key 登录
注:如果执行了第 2 步,那么远程登录普通用户需要增加 sudo
权限,不然登录后就获取不到了,如果远程登录的是 root 用户就不用!!!
如果没有 SSH Key , 先执行 ssh-keygen
进行自动生成(全程回车不需要填写内容),然后执行:
ssh-copy-id <username>@<remote_host>
完成后进行测试:ssh <username>@<remote_host>
。
修改 /etc/ssh/sshd_config
,将 PasswordAuthentication
设置为 no
:
PasswordAuthentication no
执行 systemctl restart sshd
重启 sshd
服务。
网友评论