CentOS 使用 Google Authenticator 登录验证

手机上安装Google身份验证器

安装地址:http://www.wandoujia.com/apps/com.google.android.apps.authenticator2


注意:机器上一定要关闭selinux


1、安装依赖:

yum-yinstallgccmakepam-devellibpng-devellibtoolwgetgit


2、开启EPEL源

yum–enablerepo=epel


3、或者直接安装EPEL源RPM包

# CentOS 6

rpm-Uvhhttp://mirrors.ustc.edu.cn/fedora/epel/epel-release-latest-6.noarch.rpm

# CentOS 7

rpm-Uvhhttp://mirrors.ustc.edu.cn/fedora/epel/epel-release-latest-7.noarch.rpm


4、安装Qrencode,谷歌身份验证器需要调用该程序生成二维码显示

yuminstall-yqrencode


5、安装谷歌身份验证器

gitclonehttps://github.com/google/google-authenticator-libpam.git
cdgoogle-authenticator-libpam/


编译并安装

./bootstrap.sh
./configure--prefix=/usr/local/google-authenticator
make&&makeinstall


复制google 身份验证器pam模块到系统下

cp/usr/local/google-authenticator/lib/security/pam_google_authenticator.so/lib64/security/


6、配置/etc/pam.d/sshd

authincludepassword-auth

这一行上面添加下面这行内容

authrequiredpam_google_authenticator.so

注意顺序:谷歌认证要在password-auth上面


[root@localhost ~]# cat /etc/pam.d/sshd

#%PAM-1.0
authrequiredpam_sepermit.so
authrequiredpam_google_authenticator.so
authincludepassword-auth
accountrequiredpam_nologin.so
accountincludepassword-auth
passwordincludepassword-auth
#pam_selinux.socloseshouldbethefirstsessionrule
sessionrequiredpam_selinux.soclose
sessionrequiredpam_loginuid.so
#pam_selinux.soopenshouldonlybefollowedbysessionstobeexecutedintheusercontext
sessionrequiredpam_selinux.soopenenv_params
sessionoptionalpam_keyinit.soforcerevoke
sessionincludepassword-auth


7、修改SSH服务配置/etc/ssh/sshd_config

将ChallengeResponseAuthentication no改成yes,即

ChallengeResponseAuthenticationyes


8、启用 Google Authenticator

./google-authenticator

Doyouwantauthenticationtokenstobetime-based(y/n)y

# 是否开启基于时间的认证,Y, 测试下来,如果选N,则手机上的验证码不会自动更新,使用一次后就算手动更新了验证码也无法登录

# 接下来会生成二维码,手机端扫描即可添加安全密钥

后面一路都是选择y,就可以了

注意保存好上面的5个emergency scratch codes,如果手机上的验证码不通过,可以使用上面的这个验证码,每次使用后就失效了。



linux登录客户端的设置


参考文档:

https://shenyu.me/2016/09/05/centos-google-authenticator.html

https://www.sulabs.net/?p=802

相关文章

Centos下搭建性能监控Spotlight
CentOS 6.3下Strongswan搭建IPSec VPN
在CentOS6.5上安装Skype与QQ
阿里云基于centos6.5主机VPN配置
CentOS 6.3下配置multipah
CentOS安装、配置APR和tomcat-native