Skip to content

10. Password & Account Policies

Enforcing strict password lifecycles and account expiration policies is an enterprise compliance requirement (SOC 2, ISO 27001, PCI-DSS). It ensures that forgotten, dormant, or compromised credentials cannot be used indefinitely to breach a system.


Password ageing is a security mechanism in Linux that enforces regular password rotation and controls account lifecycles. Restricting password lifespan reduces the window of vulnerability if credentials are leaked or compromised.

  • Password Expiry: The threshold date or age when a password is no longer valid, requiring a change.
  • Minimum Password Age (PASS_MIN_DAYS): The minimum number of days that must elapse before a user can change their password again. This prevents users from cycling through passwords rapidly to reuse an old favorite.
  • Maximum Password Age (PASS_MAX_DAYS): The maximum lifespan (in days) a password remains valid before mandatory rotation.
  • Warning Period (PASS_WARN_AGE): The number of days prior to password expiry during which the system issues warning notices at login.
  • Inactive Period (Account Inactivity): The grace period (in days) following password expiration during which a user may still log in and update their expired password before total account lockout occurs.
  • Account Expiry Date: An absolute calendar date upon which the account is disabled entirely, regardless of password status (ideal for contractors, interns, or temporary engagements).

10.2 System-Wide Defaults: /etc/login.defs

Section titled “10.2 System-Wide Defaults: /etc/login.defs”

Global defaults for newly provisioned user accounts are configured in /etc/login.defs.

# /etc/login.defs configuration snippet
# Maximum lifetime of a password (days)
PASS_MAX_DAYS 90
# Minimum days required between password changes (days)
PASS_MIN_DAYS 7
# Warning period before expiration (days)
PASS_WARN_AGE 7
# Minimum allowed password length
PASS_MIN_LEN 12

[!NOTE] Changes to /etc/login.defs only apply to new users created after the file is modified. Existing accounts are unaffected and must be updated individually using the chage utility.


The chage (Change Age) utility allows administrators to inspect and modify aging policies for specific accounts. It modifies fields stored in /etc/shadow.

Terminal window
sudo chage -l username

Example output:

Last password change : Oct 01, 2026
Password expires : Dec 30, 2026
Password inactive : Jan 09, 2027
Account expires : Dec 31, 2027
Minimum number of days between password change : 7
Maximum number of days between password change : 90
Number of days of warning before password expires : 7
Terminal window
# Set maximum password age (e.g. 60 days)
sudo chage -M 60 username
# Set minimum password age (e.g. 7 days)
sudo chage -m 7 username
# Set warning period (e.g. 5 days before expiry)
sudo chage -W 5 username
# Set inactive period after expiry before lockout (e.g. 10 days)
sudo chage -I 10 username
# Set absolute account expiration date (YYYY-MM-DD)
sudo chage -E 2026-12-31 username
# Force user to immediately change password on next login
sudo chage -d 0 username
Terminal window
# Enforce 60-day max age, 7-day min age, and 7-day warning
sudo chage -M 60 -m 7 -W 7 username
Terminal window
# Disable password expiration (password never expires)
sudo chage -M -1 username
# or
sudo chage -M 99999 username
# Allow immediate password changes (set min age to 0)
sudo chage -m 0 username

Running chage without flag arguments steps through an interactive prompt for each attribute:

Terminal window
sudo chage username

10.4 Under the Hood: /etc/shadow Structure

Section titled “10.4 Under the Hood: /etc/shadow Structure”

The parameters modified by chage correspond directly to fields 3 through 8 in /etc/shadow:

username:$6$...:19632:7:60:7:10:20818:
(1) (2) (3) (4)(5)(6)(7) (8) (9)
Field Meaning Associated chage Flag Associated /etc/login.defs Directive
1 Username - -
2 Encrypted password hash - -
3 Date of last password change (days since Jan 1, 1970) -d -
4 Minimum password age in days -m PASS_MIN_DAYS
5 Maximum password age in days -M PASS_MAX_DAYS
6 Warning period in days -W PASS_WARN_AGE
7 Inactive period in days before account locks -I -
8 Account expiration date (epoch days) -E -
9 Reserved field - -

10.5 The Password Ageing Lifecycle Workflow

Section titled “10.5 The Password Ageing Lifecycle Workflow”
Password Changed
│
▼
[Active Period] ──► Normal login allowed
│
▼
[Warning Period] ──► User warned at login: "Warning: your password will expire in X days"
│
▼
[Password Expired] ──► Within Inactive Grace Period: Forced to change password immediately
│
▼
[Past Inactive Period] ──► Account locked. Admin intervention required
│
▼
[Account Expired] ──► Complete access denied, regardless of password validity
  1. Password Set/Changed: Timestamp recorded as epoch days in field 3 of /etc/shadow.
  2. Within Warning Period: If current date is between (LastChange + MaxAge - WarnAge) and (LastChange + MaxAge), the user receives a warning at login.
  3. Expired Within Inactive Period: If the password has expired but the inactive grace period (-I) has not lapsed, the user is required to change their password before completing the login session.
  4. Past Inactive Period: The account is automatically locked. The user cannot log in and must contact an administrator.
  5. Account Expiry Date Reached: If field 8 has passed, the account is completely disabled.

The standard passwd command also supports password ageing flags for quick administration:

Terminal window
# Set minimum days between changes (-n is equivalent to chage -m)
sudo passwd -n 7 username
# Set maximum days between changes (-x is equivalent to chage -M)
sudo passwd -x 60 username
# Set warning days before expiration (-w is equivalent to chage -W)
sudo passwd -w 7 username
# Set inactive grace period (-i is equivalent to chage -I)
sudo passwd -i 10 username
# View account status and ageing parameters (-S)
sudo passwd -S username

Example passwd -S output:

username P 10/01/2026 7 60 7 10

(Displays username, status P=Password set / L=Locked / NP=No password, last change date, min days, max days, warning days, and inactive days).


10.7 Password Ageing Best Practices & Troubleshooting

Section titled “10.7 Password Ageing Best Practices & Troubleshooting”
  • Balanced Expiry Intervals: Choose maximum ages that balance security compliance with user disruption (typically 60 to 90 days).
  • Adequate Warning: Provide at least 7 to 14 days of advance warning to prevent accidental lockouts.
  • Enforce Minimum Age: Maintain a minimum age of at least 1 to 7 days to prevent users from rotating back to the same password immediately.
  • Automated Expiry for Contractors: Always assign an explicit account expiration date (chage -E YYYY-MM-DD) for temporary personnel.
  • Account Locked Due to Inactivity:
    Terminal window
    # Unlock account and allow immediate password update
    sudo chage -m 0 -M 60 username
    sudo passwd username
  • Auditing Expired Accounts Across the Fleet:
    Terminal window
    # Check /etc/shadow for expired accounts
    sudo awk -F: '$2 ~ /^\$/ && $5 != "" && $5 != 99999 {print $1, "Max days:", $5}' /etc/shadow

10.8 Pluggable Authentication Modules (PAM) Basics

Section titled “10.8 Pluggable Authentication Modules (PAM) Basics”

While /etc/login.defs and chage handle expiration timelines, PAM governs authentication rules, complexity enforcement, and lockout behavior.

PAM configuration files live in /etc/pam.d/ (e.g., /etc/pam.d/common-password, /etc/pam.d/system-auth, /etc/pam.d/sshd).

Each PAM configuration uses 4 module types:

  1. auth: Authenticates the user (verifies password or biometric token).
  2. account: Validates account eligibility (has password expired? Is user allowed during this time?).
  3. password: Handles password updates and enforces complexity rules.
  4. session: Sets up and tears down environment (mounts home directories, logs sessions, sets ulimits).

Enforcing Password Quality with pam_pwquality

Section titled “Enforcing Password Quality with pam_pwquality”

To prevent users from selecting weak passwords (like Password123!), Linux uses the pam_pwquality module. Configured in /etc/security/pwquality.conf:

# Minimum acceptable password length
minlen = 14
# Minimum number of digits required
dcredit = -1
# Minimum number of uppercase letters required
ucredit = -1
# Minimum number of lowercase letters required
lcredit = -1
# Minimum number of special characters required
ocredit = -1
# Max number of repeated consecutive characters
maxrepeat = 2
# Reject passwords containing the username
usercheck = 1

Protects against brute-force attacks by locking accounts after repeated authentication failures. Configured in /etc/security/faillock.conf:

# Deny access after 5 consecutive failures
deny = 5
# Lockout duration in seconds (900s = 15 minutes)
unlock_time = 900
# Track failures across root as well (optional, use with care)
even_deny_root

Managing locked users:

Terminal window
# View failed attempts for an account
sudo faillock --user alice
# Clear failures and unlock an account immediately
sudo faillock --user alice --reset