Set Existing Passwords Maximum Age

Classification:

compliance

Framework:

Control:

Description

Configure non-compliant accounts to enforce a 365-day maximum password lifetime restriction by running the following command:

$ sudo chage -M 365 USER

Rationale

Any password, no matter how complex, can eventually be cracked. Therefore, passwords need to be changed periodically. If the operating system does not limit the lifetime of passwords and force users to change their passwords, there is the risk that the operating system passwords could be compromised.

Remediation

Shell script

The following script can be run on the host to remediate the issue.

var\_accounts\_maximum\_age\_login\_defs='365'


while IFS= read -r i; do
 
 chage -M $var\_accounts\_maximum\_age\_login\_defs $i

done < <(awk -v var="$var\_accounts\_maximum\_age\_login\_defs" -F: '(/^[^:]+:[^!\*]/ && ($5 > var || $5 == "")) {print $1}' /etc/shadow)