Google-Authenticator双因子认证

20 篇文章 2 订阅

简介:Google-authenticator是基于时间的一次性密码算法(TOTP)是一种根据预共享的密钥与当前时间计算一次性密码的算法。它已被互联网工程任务组接纳为RFC 6238标准[1],成为主动开放认证(OATH)的基石,并被用于众多多重要素验证系统当中。
TOTP是散列消息认证码(HMAC)当中的一个例子。它结合一个私钥与当前时间戳,使用一个密码散列函数来生成一次性密码。由于网络延迟与时钟不同步可能导致密码接收者不得不尝试多次遇到正确的时间来进行身份验证,时间戳通常以30秒为间隔,从而避免反复尝试。

一、双因子认证搭建

搭建环境如下:CentOS Linux release 7.9.2009 (Core)、Authenticator1.0.2
不能翻墙的同学可以点击此处下载 authenticator包

Google-Authenticator默认认证方式为密码+验证码

1、安装authenticator所需依赖(此步骤非必须),然后下载Authenticator PAM插件,并按照如下步骤执行

##安装所需依赖
yum -y install wget gcc make pam-devel libpng-devel autoconf automake libtool libffi
##Google Authenticator PAM插件安装
wget https://github.com/google/google-authenticator/archive/1.02.tar.gz
##解压
tar -xzvf 1.02.tar.gz
##切换到libpam路径,并按顺序执行如下脚本
cd google-authenticator-1.02/libpam/
./bootstrap.sh
./configure
##编译并安装
make && make install

2、将生成的pam_google_authenticator.so,拷贝到/lib64/security/

安装完成后会生成/usr/local/lib/security/pam_google_authenticator.so

cp /usr/local/lib/security/pam_google_authenticator.so /lib64/security/

3、执行google-authenticator

生成秘钥的方式有两种:交互式和非交互式,两者都会在将秘钥信息生成在~/.google-authenicator中

1)非交互式:/usr/local/bin/google-authenticator -t -f -d -r 3 -R 30 -w 21
在这里插入图片描述
2)交互式切换到/usr/local/bin/路径下执行google-authenticator,并按照提示生成秘钥信息;
在这里插入图片描述

3)移动端扫描上图生成的二维码

手机端下载authenticator工具,应用商店中任何与Authenticator相关的应用都可以使用,扫描生成的二维码

4)修改/etc/pam.d/sshd

#在第一行添加
auth required pam_google_authenticator.so

5)修改/etc/ssh/sshd_config

#修改如下内容
ChallengeResponseAuthentication yes
usePAM yes

上述修改完成之后重启 systemctl restart sshd

二、验证

节点间配置免密登录,进行ssh登录,输入验证码,即可成功登录

三、扩展(秘钥+验证码)

与密码+验证码验证相比,秘钥+验证码只需将4)5)的配置做如下修改即可

4)修改/etc/pam.d/sshd

ChallengeResponseAuthentication
#与密码+验证码相比增加如下配置
AuthenticationMethods publickey,password publickey,keyboard-interactive

5)修改/etc/ssh/sshd_config

auth required pam_google_authenticator.so
#除添加authenticator PAM认证之外,还需要将密码认证关闭
#auth substack password-auth

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值