SSH Google Authenticator

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

Ubuntu 16.04.1 LTS 64bit
OpenSSH server

1、安装 SSH 服务

sudo apt update
sudo apt install openssh-server

2、安装 Google-Authenticator

sudo apt update
sudo apt install libpam-google-authenticator

3、生成密钥

google-authenticator

过程中全部按 y

4、配置手机 app

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

5、配置

sudo vim /etc/pam.d/sshd

添加:

auth required pam_google_authenticator.so

配置:

sudo vim /etc/ssh/sshd_config

修改:

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

5、重启 SSH

sudo service ssh restart

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

评论

点击加载 Giscus
或者
Charles Chin

本文作者:Charles Chin

Gemini, Millennials, Normie, Kōjigen, N24SWD, AIWS, Upekkha.

版权信息: CC BY-SA 4.0


Get in Touch

Follow me on Mastodon, orEmail,or subscribe to RSS.

Genuinely welcome! Feel free to talk to me about anything at all.

Mastodon 已复制
FOLLOW