Linux 配置Google-Authenticator TOTF认证
Google Authenticator 验证配置指南
本文将指导您如何在 CentOS 7 系统上安装和配置 Google Authenticator,以增强 SSH 登录的安全性。
1. 安装 Google Authenticator
使用以下命令安装 Google Authenticator:
rpm -ivh google-authenticator-1.04-1.el7.x86_64.rpm
2. 配置 SSHD 和 PAM
2.1 修改 PAM 配置
在 PAM 配置文件中添加 Google Authenticator 模块:
echo "auth required pam_google_authenticator.so" >> /etc/pam.d/sshd
2.2 修改 SSH 配置
编辑 SSH 配置文件以启用 PAM 和挑战响应认证:
vim /etc/ssh/sshd_config
确保以下行被设置为 yes:
UsePAM yes
ChallengeResponseAuthentication yes
2.3 重启 SSHD 服务
重启 SSH 服务以应用更改:
systemctl restart sshd
3. 配置 Google Authenticator
执行以下命令进行 Google Authenticator 的配置:
google-authenticator
注意: 在配置过程中,除了“Do you want to enable rate-limiting”选择
n以外,其他选项均选择yes。
4. 下载并配置手机应用
在手机上下载并安装身份验证应用:
- iOS: Authenticator App 或其他身份验证软件
- 安卓: Google Authenticator 或其他身份验证软件
使用应用扫描终端中显示的二维码。
5. 测试 SSH 登录
在 Xshell 或 SecureCRT 中使用 SSH 登录,设置为键盘交互模式。输入服务器密码后,再输入生成的随机验证码以成功登录服务器。
注意: 如果验证码失效,您可以通过 VNC 进入服务器,修改
/etc/ssh/sshd_config中的UsePAM为no,然后重启 SSHD 服务以恢复访问。
注意事项
- 备份密钥: 确保在配置 Google Authenticator 时备份生成的密钥,以防丢失访问权限。
- 安全性: 使用 Google Authenticator 可以显著提高 SSH 登录的安全性,但请确保您的服务器安全配置得当。
通过以上步骤,您可以成功配置 Google Authenticator,增强 SSH 登录的安全性。