双因素身份验证(2FA)为服务器访问提供了额外的安全层,即使密码泄露也能防止未授权访问。以下是在CentOS服务器上实现SSH双因素身份验证的详细步骤:
sudo yum install epel-release
sudo yum install google-authenticator qrencode
# 切换到需要配置的用户
su - yourusername
# 运行配置工具
google-authenticator
按照提示操作:
- 输入"y"生成新密钥
- 输入"y"更新~/.google_authenticator
文件
- 输入"y"禁止多次使用同一令牌
- 输入"y"允许30秒的令牌时间窗口
- 输入"y"启用速率限制
编辑/etc/pam.d/sshd
文件:
sudo vi /etc/pam.d/sshd
添加以下行:
auth required pam_google_authenticator.so
编辑/etc/ssh/sshd_config
:
sudo vi /etc/ssh/sshd_config
确保以下设置:
ChallengeResponseAuthentication yes
UsePAM yes
sudo systemctl restart sshd
编辑/etc/ssh/sshd_config
:
PubkeyAuthentication yes
PasswordAuthentication yes
AuthenticationMethods publickey,password
sudo systemctl restart sshd
sudo yum install https://dl.duosecurity.com/duo_unix-latest.x86_64.rpm
编辑/etc/duo/pam_duo.conf
:
[duo]
; Duo integration key
ikey = YOUR_INTEGRATION_KEY
; Duo secret key
skey = YOUR_SECRET_KEY
; Duo API hostname
host = YOUR_API_HOST
编辑/etc/pam.d/sshd
,添加:
auth required pam_duo.so
编辑/etc/ssh/sshd_config
:
ChallengeResponseAuthentication yes
UsePAM yes
sudo systemctl restart sshd
/var/log/secure
了解认证问题通过实施这些措施,您的CentOS服务器将获得显著增强的安全保护,有效防御凭证泄露和暴力破解攻击。