zl程序教程

您现在的位置是:首页 >  其他

当前栏目

SSH Google Authenticator

2023-02-18 16:31:25 时间

警告

本文最后更新于 2016-09-08,文中内容可能已过时。

我经常需要用 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 生成的验证码即可。