google 实现TOTP(基于时间认证)原理
1.用户须要开启Google Authenticator服务时,服务器随机生成一个相似于
『DPI45HKISEXU6HG7』的密钥,而且把这个密钥保存在.google_authenticator中。
2.客户端扫描二维码,把密钥『DPI45HKISEXU6HG7』保存在客户端,同
时客户端也能够手动输入密钥,生成验证码html
安装(centos7)
1.install
a.增长epel repo 算法
# yum install google-authenticator b.修改ssh配置,vim /etc/ssh/sshd_config 修改以下 #ChallengeResponseAuthentication yes ###容许交互 #AuthenticationMethods publickey,password publickey,keyboard-interactive #增长认证方法,默认只有密码认证才须要输入验证码,增长以后,有公钥也须要输入验证码 #重启服务 systemctl restart sshd c.在认证文件/etc/pam.d/sshd增长以下内容 #auth required pam_google_authenticator.so nullok #auth substack password-auth 放于先后取决于先输入验证码仍是先输入密码 d.生成认证文件 #google-authenticator -t -d -f -r 3 -R 30 -W #生成文件在当前家目录的.google_authenticato,同时也会弹出生成的条形码及5次紧急验证码,5次验证码使用一次少一次 #用cat .google_authenticator 打开文件后,其实内容很简单,第一行是认证生成的密钥,包括认证方法,时间等参数 #也能够一步一步生成,参考文档:https://shenyu.me/2016/09/05/centos-google-authenticator.html
#指定用户去读取认证文件及认证文件的路径vim