简介
Google Authenticator(谷歌身份验证器),是谷歌公司推出的一款动态令牌工具,解决账户使用时遭到的一些不安全的操作进行的“二次验证”,认证器基于RFC文档中的HOTP/TOTP算法实现 ,是一种从共享秘钥和时间或次数一次性令牌的算法。在实际应用中可以通过认证器方式对账户有更好的保护
下面在CentOS7下利用Google Authenticator实现SSH登录的二次身份验证
配置EPEL源
[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
google-authenticator初始化配置
- 哪个账号需要动态验证码,切换到该账号下操作进行操作
[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软件,点击+后选择“条形码扫描"添加认证条目。
Your new secret key is: UJ64PRAV7VLRY7ED4R6S43T3CM Your verification code is 851470 Your emergency scratch codes are: 43147520 72365792 24479114 16355816 30707562 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
验证
- 打开终端
- 使用Google Authenticator获取的动态码登陆
- 使用zentermlite的键盘交互认证,第一次输入账号密码,第二次数据获取的动态吗
继续阅读
- 我的QQ
- QQ扫一扫
-
- 我的头条
- 头条扫一扫
-
评论