【Linux】使用Google Authenticator 实现ssh登录双因素认证


请参考

谷歌验证 + 秘钥登录 (不用密码)
参考 https://serverfault.com/questions/629883/trying-to-get-ssh-with-public-key-no-password-google-authenticator-working-o

Ubuntu安装

apt-get install libpam-google-authenticator

  1. 修改配置文件
root@test:~# vim /etc/pam.d/sshd        #在第一行(增加以下代码 )
auth [success=done new_authtok_reqd=done default=die] pam_google_authenticator.so nullok
   
root@test:~#  vim /etc/ssh/sshd_config
ChallengeResponseAuthentication yes          #修改no为yes
UsePAM yes
AuthenticationMethods publickey,keyboard-interactive
PasswordAuthentication no   
root@test:~#  service ssh restart
  1. 设置 google-authenticator
    直接使用命令
    google-authenticator
    一路yes,ok,同意
    注意: emergency scratch codes 是紧急使用的号码,可以用这个号码,无需手机上的谷歌验证直接登录服务器,每个号码只可以用一次