[关闭]
@nalan90 2018-06-25T10:43:50.000000Z 字数 1847 阅读 1332

Google Authenticator 配置SSH动态验证码登录

自动化运维


环境部署

  1. ##1、安装依赖库
  2. [root@jdy-vpc-gw-01 ~]#yum install -y git make gcc libtool pam-devel automake autoconf ntp wget
  3. ##2、下载google-authenticator
  4. [root@jdy-vpc-gw-01 ~]#wget https://github.com/google/google-authenticator/archive/1.02.tar.gz
  5. ##3、解压缩
  6. [root@jdy-vpc-gw-01 ~]#tar -zxvf 1.02.tar.gz && cd google-authenticator-1.02/libpam/
  7. ##4、编译安装(注意是否有报错)
  8. [root@jdy-vpc-gw-01 ~]#./bootstrap.sh && ./configure --prefix=/usr/local/google-authenticator && make && make install
  9. ##5、创建软链
  10. [root@jdy-vpc-gw-01 ~]#ln -s /usr/local/google-authenticator/lib/security/pam_google_authenticator.so /usr/lib64/security/pam_google_authenticator.so
  11. ##6、编辑配置文件
  12. [root@jdy-vpc-gw-01 ~]#vim /etc/pam.d/sshd
  13. #%PAM-1.0
  14. auth required pam_google_authenticator.so nullok ##添加此行
  15. auth required pam_sepermit.so
  16. #auth substack password-auth ##注释该行
  17. auth include postlogin
  18. [root@jdy-vpc-gw-01 ~]#vim /etc/ssh/sshd_config
  19. ChallengeResponseAuthentication yes ## 将no —> yes
  20. UsePAM yes
  21. ##先验证公钥,再验证校验码
  22. AuthenticationMethods publickey,password publickey,keyboard-interactive ## 添加此行
  23. ##7、重启sshd服务
  24. [root@jdy-vpc-gw-01 ~]#systemctl restart sshd

手机客户端下载

IOS请直接使用App Store下载

image_1c0n7geb13gi8a71ej0196kh6c13.png-88.5kB

Android请在各大应用商店下载


生成二维码

  1. ##登录跳板机并执行以下命令
  2. ##to-jdy-vpc-gw-01是个人建立的别名:ssh -A test@47.xx.xx.201
  3. work:~ ys$ to-jdy-vpc-gw-01
  4. Last login: Thu Dec 7 08:16:05 2017 from 61.51.129.138
  5. Welcome to Alibaba Cloud Elastic Compute Service !
  6. [test@jdy-vpc-gw-01 ~]$ /usr/local/google-authenticator/bin/google-authenticator

执行完之后会出现以下图片所示的步骤,全部选择yes即可

image_1c0nc10261r9h1flj91b107gls1m.png-119.1kB

打开手机端的Google Authenticator,点击BEGIN SETUP

image_1c0n654qf39010jn1opb1i6bjh7m.png-280.6kB

点击Scan Barcode,扫描执行命令之后生成的二维码(不要扫描文档中的二维码)

image_1c0n668mmhgbqdodg9l3hna13.png-225.4kB

扫描完成之后会自动添加相应的记录(验证码默认的有效期为30秒),请核对用户名、服务器是否正确

image_1c0nc4f6u19v7vq6i5jkfen2313.png-84.5kB


验证是否生效

  1. ## 退出服务器
  2. [test@jdy-vpc-gw-01 ~]$ exit
  3. logout
  4. Connection to 47.xx.xx.201 closed.
  5. work:~ ys$ to-jdy-vpc-gw-01
  6. ## 再次登录服务器时要求输入验证码,输入的数字不会回显
  7. Verification code:
  8. Last login: Thu Dec 7 08:18:33 2017 from 61.51.129.138
  9. ## 登录成功
  10. Welcome to Alibaba Cloud Elastic Compute Service !

修改用户到期时间

  1. usermod -e 2017-12-31 huge
  2. chage -l huge
  3. for user in `ls /home | grep -v zhangshuang`;do usermod -e 2018-09-18 $user; done
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注