修改/etc/pam.d/common-auth文件,加上

1
auth required pam_tally2.so deny=3 unlock_time=60 even_deny_root root_unlock_time=60

重启ssh

或者,注意是或者,上面的方法感觉很容易把ssh弄的崩掉

配置私钥(用户home目录下)

1
2
3
4
5
ssh-keygen
cd .ssh
cat id_rsa.pub >> authorized_keys
chmod 600 authorized_keys
chmod 700 .ssh

编辑 /etc/ssh/sshd_config 文件

1
2
RSAAuthentication yes
PubkeyAuthentication yes

另外,留意 root 用户能否通过 SSH 登录

1
PermitRootLogin yes

密钥登录成功之后,再禁掉密码登录

1
PasswordAuthentication no

最后重启ssh