谷歌Google Authenticator实现双因素认证

参考:
https://www.cnblogs.com/hanyifeng/p/kevin4real.html

介绍:什么是双因素认证

双因素身份认证就是通过你所知道再加上你所能拥有的这二个要素组合到一起才能发挥作用的身份认证系统。双因素认证是一种采用时间同步技术的系统,采用了基于时间、事件和密钥三变量而产生的一次性密码来代替传统的静态密码。每个动态密码卡都有一个唯一的密钥,该密钥同时存放在服务器端,每次认证时动态密码卡与服务器分别根据同样的密钥,同样的随机参数(时间、事件)和同样的算法计算了认证的动态密码,从而确保密码的一致性,从而实现了用户的认证。

说白了,就像我们几年前去银行办卡送的口令牌,以及网易游戏中的将军令,在你使用网银或登陆游戏时会再让你输入动态口令的。

产品分类

市面上有基于硬件的,也有基于软件的产品,具体可以另搜啊,本人喜欢开源的东东,并找到了Google开源的二次认证系统Google Authenticator OpenSource,可以利用智能手机生产30秒动态口令配合登陆linux系统,该验证器提供了一个六位数的一次性密码。目前ios 和Android 都有客户端供于下载。

目的

1.实现登陆linux 服务器时,先输入动态口令,认证成功后,在下一步输入用户密码。如果口令失败,不会进行下一步的本地密码认证。

2.部署完成后,即使服务器不能上网,或者手机客户端不能上网,整个二步验证系统还是可以正常运行的。

基础+部署步骤

稍后补充
可以参考:https://010sec.cn/2018/02/16/useing-google-authenticator.html

1.Install the open source Google Authenticator PAM module

# 需要安装阿里云epel源
yum install google-authenticator pam-devel libpng-devel

2.Install Google Authenticator

在手机上根据自己的操作系统类型下载身份验证器(或者在谷歌浏览器端直接下载https://chrome.google.com/webstore/detail/authenticator/bhghoamapcdpbohphigoooaddinpkbai)

3.Get the verification code

# 切换用户
[user@locaohost ~]$ google-authenticator -l test@test.com -t -d -r 3 -R 30 -w 3

# 参数说明:
# google-authenticator -h 能看到可用的参数。上面命令用到的参数解释如下:
# -l 设置移动设备上的程序对应的 OTP 码的标签,便于区分不同的应用。
# -t 设置采用基于时间的验证。相应的也可以 -c 参数采用基于计数的验证。
# -d 禁止重用基于时间的验证码
# -r 限制登录频率
# -R 设置登录频率限制的时间间隔
# -w 设置时间窗的大小,主要在移动设备的时间不是准确同步的情况下比较有用

4.Change /etc/ssh/sshd_config

# 配置采用Public Key + Google Authenticator 认证
[root@server1 ~]# vim /etc/ssh/sshd_config 
Protocol 2
AuthenticationMethods  publickey,keyboard-interactive
AuthorizedKeysFile      .ssh/authorized_keys
PasswordAuthentication yes
ChallengeResponseAuthentication yes
UsePAM yes

5.Change /etc/pam.d/sshd

[root@server1 ~]# vim /etc/pam.d/sshd
# 第一行添加:
auth [success=done new_authtok_reqd=done default=die] pam_google_authenticator.so nullok

6.Restart SSH Service

systemctl restart sshd

7.生成私钥和公钥

[root@server2 ~]# yum whatprovides rz
[root@server2 ~]# yum install lrzsz -y
[root@server2 .ssh]# ssh-copy-id localhost
[root@server2 .ssh]# cp id_rsa.pub authorized_keys
[root@server2 .ssh]# sz id_rsa.pub
[root@server2 .ssh]# sz id_rsa
[root@server2 .ssh]# chmod 600 authorized_keys
[root@server2 ~]# cat .google_authenticator
KEJLQ2QW426ZNCKTHNEZEXUUE4

生成OTP码之后就可以登陆了。
在这里插入图片描述

总结

总结Google双因素认证

  1. 配置阿里源
  2. 下载软件,浏览器端的下载地址 插件https://chrome.google.com/webstore/detail/authenticator/bhghoamapcdpbohphigoooaddinpkbai
    Centos端:https://codeload.github.com/yangcvo/Google-Authenticator/zip/master
  3. 解压 安装
    需要安装wget gcc unzip bzip2 make pam-devel libpng-devel几个软件 报错可能的原因就是有软件没有装上
    unzip Google-Authenticator-master.zip
    tar jxfv libpam-google-authenticator-1.0-source.tar.bz2
    tar xf libpam-google-authenticator-1.0-source.tar
    make & make install
    之后就可以看到生成了google-authenticator命令
  4. 生成OTP码
    google-authenticator -l test@test -t -d -r 3 -R 30 -w 3
  5. 修改两个配置文件 /etc/ssh/sshd -config与/etc/pam.d/sshd_config
  6. 上传公钥与私钥 尝试连接
  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值