5.5.3 Ensure password reuse is limited

Information

The /etc/security/opasswd file stores the users' old passwords and can be checked to ensure that users are not recycling recent passwords.

remember=<5> - Number of old passwords to remember

Rationale:

Forcing users not to reuse their past 5 passwords make it less likely that an attacker will be able to guess the password.

Note: These change only apply to accounts configured on the local system.

Solution

Set remembered password history to conform to site policy.
Run the following script to add or modify the pam_pwhistory.so and pam_unix.so lines to include the remember option:

#!/usr/bin/env bash

{
file='/etc/authselect/$(head -1 /etc/authselect/authselect.conf | grep 'custom/')/system-auth'
if ! grep -Pq -- '^h*passwordh+(requisite|required|sufficient)h+pam_pwhistory.soh+([^#
r]+h+)?remember=([5-9]|[1-9][0-9]+)b.*$' '$file'; then
if grep -Pq -- '^h*passwordh+(requisite|required|sufficient)h+pam_pwhistory.soh+([^#
r]+h+)?remember=d+b.*$' '$file'; then
sed -ri 's/^s*(passwords+(requisite|required|sufficient)s+pam_pwhistory.sos+([^#
r]+s+)?)(remember=S+s*)(s+.*)?$/1 remember=5 5/' $file
elif grep -Pq -- '^h*passwordh+(requisite|required|sufficient)h+pam_pwhistory.soh+([^#
r]+h+)?.*$' '$file'; then
sed -ri '/^s*passwords+(requisite|required|sufficient)s+pam_pwhistory.so/ s/$/ remember=5/' $file
else
sed -ri '/^s*passwords+(requisite|required|sufficient)s+pam_unix.so/i password required pam_pwhistory.so remember=5 use_authtok' $file
fi
fi
if ! grep -Pq -- '^h*passwordh+(requisite|required|sufficient)h+pam_unix.soh+([^#
r]+h+)?remember=([5-9]|[1-9][0-9]+)b.*$' '$file'; then
if grep -Pq -- '^h*passwordh+(requisite|required|sufficient)h+pam_unix.soh+([^#
r]+h+)?remember=d+b.*$' '$file'; then
sed -ri 's/^s*(passwords+(requisite|required|sufficient)s+pam_unix.sos+([^#
r]+s+)?)(remember=S+s*)(s+.*)?$/1 remember=5 5/' $file
else
sed -ri '/^s*passwords+(requisite|required|sufficient)s+pam_unix.so/ s/$/ remember=5/' $file
fi
fi
authselect apply-changes
}

Additional Information:

Additional module options may be set, recommendation only covers those listed here.

NIST SP 800-53 Rev. 5:

IA-5(1)

See Also

https://workbench.cisecurity.org/files/3939