1 安装google-authenticator
1.1 配置EPEL源
推荐阿里EPEL源,传送门:
https://blog.csdn.net/qq_29974229/article/details/119447901
1.2 安装google-authenticator手机客户端
https://github.com/google/google-authenticator-android
1.3 服务器安装google-authenticator
yum install google-authenticator -y
1.4 绑定生成随机密码
google-authenticator
复制链接到浏览器
绑定后手机上每30秒刷新1次6位数密码
将它填入到
万一手机丢了可以用这个码登录,但每个码只能用1次,使用后即消失
后面所有问题都选y即可.
1.5 修改配置文件使pam插件生效
sed -i '1a\auth required pam_google_authenticator.so' /etc/pam.d/sshd
sed -ir 's/^ChallengeResponseAuthentication no/ChallengeResponseAuthentication yes/' /etc/ssh/sshd_config
1.6 重启sshd服务
systemctl restart sshd
2 登录测试
题外话:试了下Putty和SecureCrt都没问题,但Xshell始终无法登陆,如果有知道原因的小伙伴记得给我留言.谢谢