安装方式一:
yum -y install google-authenticator
注: 如果没有找到, 要安装 epel-release 源 ,yum -y install epel-release
安装方式二:
- yum install -y Git make gcc libtool pam-devel qrencode ntpdate
- Git clone https://github.com/google/google-authenticator-libpam.git
- cd google-authenticator-libpam/
- ./Bootstrap.sh
- ./configure
- make
- make install
配置 SSH
VIM /etc/SSH/sshd_config
修改如下的配置项:
- ChallengeResponseAuthentication yes
- UsePAM yes
配置 PAM
- VIM /etc/pam.d/sshd
- #%PAM-1.0
- auth required pam_google_authenticator.so #添加至第一行
重启 SSH
systemctl restart sshd
配置 google authenticator
首要条件: 先切换到你需要设置的帐号
- Do you want authentication tokens to be time-based (y/n) #基于时间生成身份验证
- # 已经安装 qrencode 会产生一个二维码, 二维码连接也可以 URL 显示
- Your new secret key is :*********** # 密钥 key
- # 使用移动端的 authenticator 扫描二维码或者输入密钥 key
- # 得到 code from App :
- Enter code from App (-1 to skip): #输入得到的 code, 动态验证
- Your emergency scratch codes are: # 生成 5 个紧急救助码
- Do you want me to update your "/root/.google_authenticator" file? (y/n) #一直确认下去
- # 生成了一个 .google_authenticator 文件
- your chances to notice or even prevent man-in-the-middle attacks (y/n) #一直确认下去
- Do you want to do so? (y/n) #一直确认下去
- Do you want to enable rate-limiting? (y/n) #设置完成
- # 上面的意思大概为: 禁止多次使用相同的身份验证, 限制每 30 秒登录一次, 移动端每 30 秒更新一次, 移动端和客户端时间误差 30 秒, 30 秒内不能超过 3 次登录.
如果需要删除一个用户的 Google 验证, 删除这个用户下产生的 home/.google_authenticator 文件即可
来源: http://www.bubuko.com/infodetail-3105267.html