linux极简小知识:27、CentOS / RHE 7 如何阻止用户使用最近10次使用过的密码【译】
翻译自CentOS / RHE 7 : How to Prevent Users from Using the Last 10 Passwords
介绍
此处的要求是,在设置新密码时,用户不应该使用最近10次使用过的密码。如果用户尝试设置最近10次使用过的密码,应该得到一个如下的错误:
Changing password for user test. New UNIX password: Retype new UNIX password: <strong>Password has been already used.</strong> passwd: all authentication tokens updated successfully. 复制代码
这是一个安全措施,通过在每次密码过期时保持用户设置信息,确保密码不会被黑。
修改 /etc/pam.d/system-auth
文件实现
该密码限制,可以按照如下设置实现:
修改文件 /etc/pam.d/system-auth, 使其在第一次出现密码需求的行后,包含 pam 模块 pam_pwhistory
。
pam_pwhistory.so
的设置为:password requisite pam_pwhistory.so debug use_authtok remember=10 retry=3
如下:
# cat /etc/pam.d/system-auth #%PAM-1.0 # This file is auto-generated. # User changes will be destroyed the next time authconfig is run. auth required pam_env.so auth sufficient pam_unix.so nullok try_first_pass auth requisite pam_succeed_if.so uid >= 1000 quiet_success auth required pam_deny.so account required pam_unix.so account sufficient pam_localuser.so account sufficient pam_succeed_if.so uid < 1000 quiet account required pam_permit.so password requisite pam_pwquality.so try_first_pass local_users_only retry=3 authtok_type= # 添加配置 password requisite pam_pwhistory.so debug use_authtok remember=10 retry=3 password sufficient pam_unix.so sha512 shadow nullok try_first_pass use_authtok password required pam_deny.so session optional pam_keyinit.so revoke session required pam_limits.so -session optional pam_systemd.so session [success=1 default=ignore] pam_succeed_if.so service in crond quiet use_uid session required pam_unix.so 复制代码
如下,红色为添加的配置:
测试修改用户密码
# passwd test [Enter already used password] 复制代码
然后就可看到,系统抛出一个错误,提示该密码在过去已经被使用:
Changing password for user test. New UNIX password: Retype new UNIX password: Password has been already used. passwd: all authentication tokens updated successfully.</pre> 复制代码
相对来说这是一个很简单也很实用的功能!
作者:代码迷途
链接:https://juejin.cn/post/7020911426675933192