首先,我们需要检查当前系统的用户认证配置。
sudo cat /etc/pam.d/common-auth
sudo cat /etc/shadow示例:在 /etc/pam.d/common-password 文件中添加或修改以下行:
password requisite pam_cracklib.so retry=3 minlen=12 difok=3 ucredit=-1 lcredit=-1 dcredit=-1 ocredit=-1示例:在 /etc/login.defs 文件中设置密码过期策略:
PASS_MAX_DAYS 90
PASS_MIN_DAYS 7
PASS_WARN_AGE 14示例:在 /etc/pam.d/common-auth 文件中添加或修改以下行:
auth required pam_tally2.so onerr=fail deny=5 unlock_time=900示例:安装并配置 Google Authenticator:
sudo apt-get install libpam-google-authenticator
google-authenticator编辑 /etc/pam.d/sshd 文件,添加以下行:
auth required pam_google_authenticator.so 示例:生成 SSH 密钥对:
ssh-keygen -t rsa -b 4096 将公钥复制到目标主机:
ssh-copy-id user@target_host 编辑 /etc/ssh/sshd_config 文件,禁用密码认证:
PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no重启 SSH 服务:
sudo systemctl restart sshd定期检查和更新用户认证策略是非常重要的,以确保系统始终处于最佳的安全状态。
使用图形化或命令行的管理工具,如 pam-config 或 fail2ban,可以帮助您更方便地管理和维护用户认证策略。
sudo apt-get install fail2ban/etc/fail2ban/jail.conf 文件,启用和配置需要监控的服务:[sshd]
enabled = true
port = ssh
logpath = /var/log/auth.log
maxretry = 5
bantime = 900启动并设置开机自启:
sudo systemctl start fail2ban
sudo systemctl enable fail2ban原创声明:本文系作者授权腾讯云开发者社区发表,未经许可,不得转载。
如有侵权,请联系 cloudcommunity@tencent.com 删除。