如何在Linux中防止用户再次使用旧密码(或者重用)
时间:2020-02-23 14:40:15 来源:igfitidea点击:
我们希望在密码策略中实施特定的密码限制。
我们希望防止用户在分配新密码时使用旧密码,即在分配新密码时重复使用旧密码。
防止用户使用旧密码
例如,我使用了密码test123,因此下次我分配新密码时,将不允许我再次使用test123.
但是直到历史阈值将保持这个上限。
假设我希望防止用户使用旧密码(直到第5个旧密码),可以使用比第5个密码旧的密码。
例如,以下是我在一段时间内为hynman用户分配的密码列表
test1 test2 test3 test4 test5 test6
因此,下次" hynman"用户可以重新使用" test1"作为密码,因为它是" 6th"旧密码,但不允许使用" test2"作为新密码。
要实现此限制,我们必须在/etc/pam.d/system-auth和/etc/pam.d/password-auth中插入以下内容(在pam_pwquality.so之后):
password requisite pam_pwhistory.so remember=5 use_authtok
从pam_unix的手册页中
use_authtok When password changing enforce the module to set the new password to the one provided by a previously stacked password module
让我们来看这个生动的例子。
我将尝试使用'hynman
'用户执行SSH。
由于强制执行密码更改以演示本文,因此用户'hynman'必须更改其密码。
[root@rhel-7 ~]# ssh [email protected] [email protected]'s password: You are required to change your password immediately (root enforced) Last login: Sat Aug 31 18:05:47 2019 from 10.0.2.11 WARNING: Your password has expired. You must change your password now and login again! Changing password for user hynman. Changing password for hynman. (current) UNIX password: New password: Retype new password: Password has been already used. Choose another.
如果hynman
尝试使用相同的旧密码,那么他将得到突出显示的错误。