google认证配置说明
在服务器的登陆过程中,可以使用google认证的方式来加强服务器的安全。下面简单的介绍下google-authenticator的使用方法。
1、安装
在安装之前解决掉相关的依赖
yum -y install epel*
yum -y install pam-devel
下载google-authenticator-master.zip文件。
利用rz上传到指定的文件夹。
cd /usr/local/src
unzip google-authenticator-master.zip
cd google-authenticator-master/libpam
make install
编译安装完成之后会生成google-authenticator,pam_google_authenticator.so等几个文件。
2、安装完成之后,会在/lib64/security会生成相关的库文件。
下面修改ssh的配置使其支持google认证
1、vim /etc/pam.d/sshd
auth required pam_google_authenticator.so
将上面认证添加到文件中去
2、vim /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
将上面的语句添加上去,然后重启ssh服务
3、生成google-authenticator的二维码
执行google-authenticator 生成相应的二维码文件。
如果需要回答yes/no都是yes,然后将https的连接地址在google浏览器打开(如果地址打不开的请翻墙),这时候会生成一个二维码。接下来我们只需要下手机下载google-authenticator APP扫面二维码,就能获得到相应账户的动态密码了。
4、在登陆的过程中,有可能会出现登陆不上去的情况发生。查看日志,日志报错误为:
Aug 8 23:02:03 node2 sshd(pam_google_authenticator)[2161]: Invalid verification code
Aug 8 23:02:06 node2 sshd[2159]: error: PAM: Cannot make/remove an entry for the specified session for root from 192.168.10.161
Aug 8 23:03:12 node2 sshd(pam_google_authenticator)[2163]: Invalid verification code
Aug 8 23:03:12 node2 sshd(pam_google_authenticator)[2163]: Secret file "/root/.google_authenticator" changed while trying to use scratch code
Aug 8 23:03:15 node2 sshd[2159]: error: PAM: Cannot make/remove an entry for the specified session for root from 192.168.10.161
Aug 8 23:03:20 node2 sshd(pam_google_authenticator)[2170]: Invalid verification code
Aug 8 23:03:23 node2 sshd[2159]: error: PAM: Cannot make/remove an entry for the specified session for root from 192.168.10.161
Aug 9 14:06:40 node2 sshd[2154]: Received signal 15; terminating.
Aug 9 14:06:40 node2 sshd[2259]: Server listening on 0.0.0.0 port 22.
Aug 9 14:06:40 node2 sshd[2259]: Server listening on :: port 22.
Aug 9 14:06:59 node2 sshd[2262]: Address 192.168.10.161 maps to localhost, but this does not map back to the address - POSSIBLE BRE
如果出现了上面的错误,是时间的问题。这时候需要手动同步下时间就可以了
ntpdate pool.ntp.org
这时候就可以进行登陆了。如果利用crt或者是xshell进行登陆的时候还有注意设置等了的方式改为 Keyboard Interactive。