安装 Google Authenticator
安装 Google Authenticator
sudo apt install libpam-google-authenticator
配置 Google Authenticator
google-authenticator -t -f -d -w 3 -e 5 -r 3 -R 15
选项说明: -t : 使用 TOTP 验证
-f : 将配置保存到 ~/.google_authenticator
-d : 不允许重复使用以前使用的令牌
-w 3 : 允许的令牌的窗口大小。 默认情况下,令牌每 30 秒过期一次。 窗口大小 3 允许在当前令牌之前和之后使用令牌进行身份验证以进行时钟偏移
-e 5 : 生成 5 个紧急备用代码
-r 3 -R 15 : 限速,每 15 秒允许 3 次登录
修改 PAM 配置
vi /etc/pam.d/sshd
在@include common-auth 后添加
auth required pam_google_authenticator.so
确保文件如下所示
# 先走系统密码验证
@include common-auth
# 再走 Google Authenticator
auth required pam_google_authenticator.so
修改sshd
vi /etc/ssh/sshd_config
修改KbdInteractiveAuthentication 为 yes
KbdInteractiveAuthentication yes
添加或修改以下内容
ChallengeResponseAuthentication yes
UsePAM yes
PasswordAuthentication yes
重启sshd
sudo systemctl restart ssh