1 、安装
方案一:
yum -y install google-authenticator
注:如果没有找到,要安装epel-release源 ,yum -y install epel-release
方案二:
或者下载压缩包
yum -y install mercurial pam-devel bzip2
安装Google Authenticator:
https://codeload.github.com/yangcvo/Google-Authenticator/zip/master //windows端下载直接传到服务器上
unzip Google-Authenticator-master.zip
cd Google-Authenticator-master/
tar -jxf libpam-google-authenticator-1.0-source.tar.bz2
cd libpam-google-authenticator-1.0
make
make install
2、配置
方案一:
SSH登录时调用google-authenticator模块,编辑:
/etc/pam.d/sshd
第一行添加:
#%PAM-1.0
auth required pam_google_authenticator.so
修改SSH配置文件:
vim /etc/ssh/sshd_config
添加或修改以下内容:
ChallengeResponseAuthentication yes
UsePAM yes
重启SSH:
systemctl restart sshd
方案二:
SSH免秘钥登录调用谷歌验证
vim /etc/ssh/sshd_config
RSAAuthentication yes
PubkeyAuthentication yes
ChallengeResponseAuthentication yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no
UsePAM yes
vim /etc/pam.d/sshd
#%PAM-1.0
auth sufficient pam_google_authenticator.so //新加一行
auth required pam_sepermit.so
auth substack password-auth
auth include postlogin
重启SSH:
systemctl restart sshd
3、生成
完成后可通过google-authenticator命令对当前用户创建随机密码,也会生成一个二维码,之后选项都选择yes即可;
创建后在家目录下有个隐藏文件为.google-authenticator的文件,记住第一行私钥
4、下载
然后就可以在手机上安装google-authenticator客户端,通过输入私钥即可实时显示密码,也可以使用二维码扫码实现
以后再远程登录的时候就会弹出验证码,而要输入客户端上实时产生的动态验证码才能进行登录;