Centos7 SSH增加多因子验证(google-authenticator)
按照一些文章开启ssh的多因子验证,发现不起作用,参考了一些国外的文章才起作用,记录下。
安装
1 | yum install epel-release |
配置
google-authenticator
1 | google-authenticator |
用2FA客户端(比如:Stratum - Authenticator APP)扫描二维码,保存
记得备份下
/root/.google_authenticator文件
配置/etc/pam.d/sshd
1 | %PAM-1.0 |
#auth substack password-auth注释掉很关键
很多文章中没有这一步!!!
配置/etc/ssh/sshd_config
1 | ChallengeResponseAuthentication设置为yes |
AuthenticationMethods publickey,password publickey,keyboard-interactive新加的一行很关键
很多文章中没有这一步!!!
运行
systemctl restart sshd
1 | ssh -p 22 root@xxxx |
需要注意的是,默认情况下一个code最多只能验证3次。
验证不通过的话就等下一个code