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.
10.1 Password Ageing Fundamentals
Section titled “10.1 Password Ageing Fundamentals”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.
Key Lifecycle Parameters
Section titled “Key Lifecycle Parameters”- 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 lengthPASS_MIN_LEN 12[!NOTE] Changes to
/etc/login.defsonly apply to new users created after the file is modified. Existing accounts are unaffected and must be updated individually using thechageutility.
10.3 User-Level Ageing: The chage Command
Section titled “10.3 User-Level Ageing: The chage Command”The chage (Change Age) utility allows administrators to inspect and modify aging policies for specific accounts. It modifies fields stored in /etc/shadow.
Inspecting Account Expiry Status
Section titled “Inspecting Account Expiry Status”sudo chage -l usernameExample output:
Last password change : Oct 01, 2026Password expires : Dec 30, 2026Password inactive : Jan 09, 2027Account expires : Dec 31, 2027Minimum number of days between password change : 7Maximum number of days between password change : 90Number of days of warning before password expires : 7Modifying Specific Ageing Parameters
Section titled “Modifying Specific Ageing Parameters”# 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 loginsudo chage -d 0 usernameCombined Production Configuration
Section titled “Combined Production Configuration”# Enforce 60-day max age, 7-day min age, and 7-day warningsudo chage -M 60 -m 7 -W 7 usernameDisabling or Relaxing Password Ageing
Section titled “Disabling or Relaxing Password Ageing”# Disable password expiration (password never expires)sudo chage -M -1 username# orsudo chage -M 99999 username
# Allow immediate password changes (set min age to 0)sudo chage -m 0 usernameInteractive Mode
Section titled “Interactive Mode”Running chage without flag arguments steps through an interactive prompt for each attribute:
sudo chage username10.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- Password Set/Changed: Timestamp recorded as epoch days in field 3 of
/etc/shadow. - Within Warning Period: If current date is between
(LastChange + MaxAge - WarnAge)and(LastChange + MaxAge), the user receives a warning at login. - 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. - Past Inactive Period: The account is automatically locked. The user cannot log in and must contact an administrator.
- Account Expiry Date Reached: If field 8 has passed, the account is completely disabled.
10.6 Setting Ageing Controls with passwd
Section titled “10.6 Setting Ageing Controls with passwd”The standard passwd command also supports password ageing flags for quick administration:
# 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 usernameExample 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”Best Practices
Section titled “Best Practices”- 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.
Troubleshooting Locked Accounts
Section titled “Troubleshooting Locked Accounts”- Account Locked Due to Inactivity:
Terminal window # Unlock account and allow immediate password updatesudo chage -m 0 -M 60 usernamesudo passwd username - Auditing Expired Accounts Across the Fleet:
Terminal window # Check /etc/shadow for expired accountssudo 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 Architecture
Section titled “PAM Architecture”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:
auth: Authenticates the user (verifies password or biometric token).account: Validates account eligibility (has password expired? Is user allowed during this time?).password: Handles password updates and enforces complexity rules.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 lengthminlen = 14
# Minimum number of digits requireddcredit = -1
# Minimum number of uppercase letters requireducredit = -1
# Minimum number of lowercase letters requiredlcredit = -1
# Minimum number of special characters requiredocredit = -1
# Max number of repeated consecutive charactersmaxrepeat = 2
# Reject passwords containing the usernameusercheck = 1Account Lockout with pam_faillock
Section titled “Account Lockout with pam_faillock”Protects against brute-force attacks by locking accounts after repeated authentication failures.
Configured in /etc/security/faillock.conf:
# Deny access after 5 consecutive failuresdeny = 5
# Lockout duration in seconds (900s = 15 minutes)unlock_time = 900
# Track failures across root as well (optional, use with care)even_deny_rootManaging locked users:
# View failed attempts for an accountsudo faillock --user alice
# Clear failures and unlock an account immediatelysudo faillock --user alice --reset