1、安装 libpam-google-authenticator

sudo apt update
sudo apt install libpam-google-authenticator -y

2、为每个用户生成 TOTP 密钥

google-authenticator

3、回答显示的问题,默认y就可以。
4、使用微软或者谷歌验证器扫码。
5、拍照记录应急验证码。
6、配置 PAM 模块启用 TOTP

sudo nano /etc/pam.d/sshd

在文件最上方添加以下内容:

auth required pam_google_authenticator.so nullok

如果必须使用两步验证,则:

auth required pam_google_authenticator.so

7、编辑ssh配置。

sudo nano /etc/ssh/sshd_config

修改以下内容:

ChallengeResponseAuthentication yes
UsePAM yes
PasswordAuthentication yes  # 如使用公钥登录可为 no
KbdInteractiveAuthentication yes  # 这一行必不可少,否则不能使用xshell,termius等

8、重启ssh服务,使上述配置生效。

sudo systemctl restart ssh

标签: none

评论已关闭