目录
- 一、问题背景
- 二、问题分析
- 三、修复思路
- 四、整改实施
- 五、验证修复结果
- 六、模块检查
- 七、特殊发现:authselect
- 八、自动化修复脚本
- 九、修复效果
- 十、总结
一、问题背景
在企业 Linux 安全基线扫描过程中,发现服务器存在如下告警:
Category : Password Requirements Name : Password Min History LINUX-RHEL-MULTI Severity : Medium该问题属于账户密码策略类基线检查项,要求系统禁止用户重复使用最近使用过的历史密码。
虽然该问题不会影响业务运行,但会导致:
- 安全基线检查不通过
- 安全审计不通过
- 生产环境合规性验收失败
因此需要进行整改。
二、问题分析
初始检查时,PAM 配置如下:
password requisite pam_pwquality.so try_first_pass local_users_onlyretry=3authtok_type=password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadow password required pam_deny.so查看配置:
grepremember /etc/pam.d/system-auth返回为空:
<无输出>查看 Password History 模块:
greppwhistory /etc/pam.d/system-auth返回为空:
<无输出>说明系统虽然已经配置了密码复杂度策略:
pam_pwquality.so但并未配置密码历史策略:
pam_pwhistory.so因此被安全扫描工具判定为:
Password Min History LINUX-RHEL-MULTI不符合基线要求。
三、修复思路
企业基线要求:
最近8次密码不得重复使用对应 PAM 配置为:
password requisite pam_pwhistory.so try_first_pass local_users_only enforce_for_rootretry=3remember=8password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadowremember=8其中:
remember=8表示:
禁止使用最近8次历史密码四、整改实施
4.1 备份配置
修改前先备份:
cp-p/etc/pam.d/system-auth\/etc/pam.d/system-auth.bak.$(date+%F_%H%M%S)4.2 修改 PAM 配置
编辑文件:
vi/etc/pam.d/system-auth将 Password 段调整为:
password requisite pam_pwquality.so try_first_pass local_users_onlyretry=3authtok_type=password requisite pam_pwhistory.so try_first_pass local_users_only enforce_for_rootretry=3remember=8password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadowremember=8password required pam_deny.so注意:
remember=8必须写在pam_unix.so这一行末尾。
错误写法:
password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadowremember=8会导致 PAM 配置格式异常。
五、验证修复结果
验证 Password History 配置:
grep-E"remember|pwhistory"/etc/pam.d/system-auth期望输出:
password requisite pam_pwhistory.so try_first_pass local_users_only enforce_for_rootretry=3remember=8password sufficient pam_unix.so try_first_pass use_authtok nullok sha512 shadowremember=8六、模块检查
确认 Rocky Linux 已安装对应模块:
ls-l/usr/lib64/security/pam_pwhistory.so返回:
/usr/lib64/security/pam_pwhistory.so说明模块存在,可以正常加载。
七、特殊发现:authselect
检查过程中发现文件头部存在如下提示:
User changes will be destroyed the next time authselect is run.说明当前系统采用authselect管理 PAM 配置。
理论上推荐使用authselect统一维护配置。
但在实际安全整改场景中,如果目标仅为快速通过安全基线扫描,且近期不会执行authselect apply-changes或者系统模板重建操作,则直接修改/etc/pam.d/system-auth即可满足整改要求。
八、自动化修复脚本
对于多台 Rocky Linux 服务器,可采用 Shell 自动修复。
#!/bin/bashset-ePAM_FILE="/etc/pam.d/system-auth"BACKUP_FILE="/etc/pam.d/system-auth.bak.$(date+%F_%H%M%S)"cp-p"${PAM_FILE}""${BACKUP_FILE}"sed-i'/pam_pwhistory.so/d'"${PAM_FILE}"sed-i'/password.*pam_unix.so/{ /remember=8/! s/$/ remember=8/ }'"${PAM_FILE}"sed-i'/password.*pam_pwquality.so/a\ password requisite pam_pwhistory.so try_first_pass local_users_only enforce_for_root retry=3 remember=8 '"${PAM_FILE}"echo"Verification:"grep-E"remember|pwhistory""${PAM_FILE}"执行:
chmod+x fix_password_history.sh ./fix_password_history.sh即可完成整改。
九、修复效果
修复后:
Password Min History LINUX-RHEL-MULTI检查项满足要求。
影响范围:
账户密码策略不会影响:
- SSH 登录
- Nginx
- Web 服务
- 数据库
- 应用程序
- 业务访问
无需执行reboot,无需执行systemctl restart sshd,无需执行systemctl restart nginx。
PAM 配置修改后立即生效。
十、总结
本次整改的根因并非密码复杂度不足,而是缺失密码历史策略配置。系统已启用pam_pwquality.so用于密码复杂度控制,但未启用pam_pwhistory.so用于历史密码控制。
通过增加pam_pwhistory.so并统一设置remember=8,即可满足企业安全基线关于 Password Min History 的检查要求,实现最小改动、零业务影响和快速通过安全复扫的目标。