首先安装Google Authenticator PAM模块,运行google-authenticator配置动态验证码,编辑/etc/pam.d/sshd添加auth required pam_google_authenticator.so,再修改/etc/ssh/sshd_config启用ChallengeResponseAuthentication和AuthenticationMethods,最后重启sshd服务完成双因素认证配置。
在Linux系统中配置双因素认证(2FA)能显著提升服务器的安全性。通过集成Google身份验证器,用户在登录时除了输入密码,还需提供一个动态生成的验证码。以下是基于Google Authenticator的双因素认证配置方法,适用于大多数主流Linux发行版(如Ubuntu、CentOS等)。
双因素认证依赖于PAM(Pluggable Authentication Modules)机制。首先需要安装Google Authenticator的PAM支持库。
在基于Debian的系统(如Ubuntu)上执行:
sudo apt update sudo apt install libpam-google-authenticator
在基于RHEL的系统(如CentOS、Rocky Linux)上执行:
sudo yum install epel-release sudo yum install google-authenticator </font>
sudo dnf install epel-release sudo dnf install google-authenticator </font>
切换到目标用户(通常是需要远程登录的账户),运行初始化命令:
google-authenticator
系统会提示以下问题,建议按如下选择:
命令执行后会生成一个二维码和一组密钥、恢复码。使用Google Authenticator、Microsoft Authenticator等App扫描二维码完成绑定。
需要修改SSH服务的PAM配置文件,启用Google Authenticator验证。编辑PAM配置:
sudo nano /etc/pam.d/sshd
在文件开头添加以下行:
auth required pam_google_authenticator.so
注意:不要删除原有的auth行,此行确保在密码验证前先检查2FA码。
编辑SSH主配置文件:
sudo nano /etc/ssh/sshd_config
确保以下配置项已设置:
ChallengeResponseAuthentication yes AuthenticationMethods publickey,keyboard-interactive
如果你使用密码登录而非SSH密钥,可设置为:
AuthenticationMethods password,keyboard-interactive
保存后重启SSH服务:
sudo systemctl restart sshd
配置完成后,用户在SSH登录时需依次输入密码(或使用密钥)和Google Authenticator生成的6位动态码。整个过程无需额外服务,安全且轻量。
基本上就这些。只要时间同步准确,手机App绑定正确,2FA就能稳定运行。建议为关键用户启用,并保留恢复码以防丢失设备。
以上就是如何在Linux中配置双因素认证 Linux Google验证器集成的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号