CentOS7使用Google Authenticator

IT 2020年8月20日15:05:19CentOS评论6,4472524字阅读8分24秒阅读模式


Google Authenticator(谷歌身份验证器),是谷歌公司推出的一款动态令牌工具,解决账户使用时遭到的一些不安全的操作进行的“二次验证”,认证器基于RFC文档中的HOTP/TOTP算法实现 ,是一种从共享秘钥和时间或次数一次性令牌的算法。在实际应用中可以通过认证器方式对账户有更好的保护

下面在CentOS7下利用Google Authenticator实现SSH登录的二次身份验证


[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# curl -o /etc/yum.repos.d/CentOS-Base.repo http://mirrors.aliyun.com/repo/Centos-7.repo
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# curl -o /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# yum makecache

安装Google Authenticator

[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# yum install google-authenticator -y


  • 哪个账号需要动态验证码,切换到该账号下操作进行操作
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# google-authenticator

Do you want authentication tokens to be time-based (y/n) y
  • 屏幕提示Do you want authentication tokens to be time-based (y/n) ,回答y选用基于时间的token
  • 屏幕提示二维码,拿出手机打开google authenticator软件,点击+后选择“条形码扫描"添加认证条目。

CentOS7使用Google Authenticator

CentOS7使用Google Authenticator

Your new secret key is: UJ64PRAV7VLRY7ED4R6S43T3CM
Your verification code is 851470
Your emergency scratch codes are:

Do you want me to update your "/root/.google_authenticator" file? (y/n) y

Do you want to disallow multiple uses of the same authentication
token? This restricts you to one login about every 30s, but it increases
your chances to notice or even prevent man-in-the-middle attacks (y/n) y

By default, a new token is generated every 30 seconds by the mobile app.
In order to compensate for possible time-skew between the client and the server,
we allow an extra token before and after the current time. This allows for a
time skew of up to 30 seconds between authentication server and client. If you
experience problems with poor time synchronization, you can increase the window
from its default size of 3 permitted codes (one previous code, the current
code, the next code) to 17 permitted codes (the 8 previous codes, the current
code, and the 8 next codes). This will permit for a time skew of up to 4 minutes
between client and server.
Do you want to do so? (y/n) y

If the computer that you are logging into isn't hardened against brute-force
login attempts, you can enable rate-limiting for the authentication module.
By default, this limits attackers to no more than 3 login attempts every 30s.
Do you want to enable rate-limiting? (y/n) y
  • 新建ssh连接(不要关闭当前的防止无法访问)测试配置是否成功。
  • 修改SSH登录相关配置文件参数
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# vim /etc/pam.d/sshd
auth required pam_google_authenticator.so
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# vim /etc/ssh/sshd_config
ChallengeResponseAuthentication yes
[root@iZ2ze2wuri2qoajwrtuzzyZ ~]# service sshd restart
Redirecting to /bin/systemctl restart sshd.service


  • 打开终端

CentOS7使用Google Authenticator

  • 使用Google Authenticator获取的动态码登陆
  • 使用zentermlite的键盘交互认证,第一次输入账号密码,第二次数据获取的动态吗

CentOS7使用Google Authenticator

CentOS7使用Google Authenticator

  • 我的QQ
  • QQ扫一扫
  • weinxin
  • 我的头条
  • 头条扫一扫
  • weinxin
  • 本文由 发表于 2020年8月20日15:05:19
  • 除非特殊声明,本站文章均为原创,转载请务必保留本文链接
Teambition 网盘与阿里云盘数据合并说明 CentOS

Teambition 网盘与阿里云盘数据合并说明

前言 Teambition 团队是阿里巴巴的一个创新产品团队,除了你熟悉的 Teambition App,「阿里云盘」也是我们的作品,它们都属于阿里云正在打造的新一代「云服务」。 过去几个月,我们投入...
CentOS8安装Jenkins CentOS


简述 Jenkins 是最流行的,开源的,基于 Java 的自动化服务器,它允许你很容易的设置一个持续集成和持续发布的管道。 持续集成 (CI)是一个 DevOps 实践。当团队成员正常提交代码到版本...