SSH Google Authenticator

OpenAI ChatGPT3.5
Pre-generated by ChatGPT 3.5
这篇文章介绍了如何使用SSH Google Authenticator进行双重验证。文章分为五个步骤:安装SSH服务、安装Google-Authenticator、生成密钥、配置手机app和配置。作者介绍了使用Google的双重验证的原因,并说明了适用于Ubuntu VPS的设置方法。最后,作者提到在使用时需要输入手机app生成的验证码。

我经常需要用 SSH 连加家到自己的电脑上,如果单独用密码验证,存在很多安全隐患,如果用密钥,又很麻烦,所以我选择的是用 Google 的双重验证。顺便换了一个非 22 端口。
下面的方法同样适用于 Ubuntu VPS,我的几个 VPS 都是这样设置的。

Ubuntu 16.04.1 LTS 64bit
OpenSSH server

1
2
sudo apt update
sudo apt install openssh-server
1
2
sudo apt update
sudo apt install libpam-google-authenticator
1
google-authenticator

过程中全部按 y

Google-Authenticator洋葱Authy身份宝 等扫描上一步生成的二维码即可。
我个人使用的是 Authy。

1
sudo vim /etc/pam.d/sshd

添加:

1
auth required pam_google_authenticator.so

配置:

1
sudo vim /etc/ssh/sshd_config

修改:

1
2
ChallengeResponseAuthentication yes #改为 yes
port 22222 #SSH 默认使用 22 端口,这里看个人喜好修改成其他的或不修改

5、重启 SSH

1
sudo service ssh restart

使用时,Verification code:输入手机 app 生成的验证码即可。