Kahibaro
Discord Login Register

Password policies

Why Password Policies Matter

Password policies define how user passwords must be created, stored, and maintained on a system. On Linux servers, they help:

This chapter focuses on configuring and inspecting password policies on typical Linux systems. User and group concepts, sudo, and basic account management are covered in other chapters.

Core Elements of a Password Policy

Common policy elements you’ll encounter:

Linux implements these using Pluggable Authentication Modules (PAM) plus a few configuration files and tools.

Files and Tools Related to Password Policies

You’ll work mainly with:

CLI tools:

Password Aging: System‑Wide Defaults with `login.defs`

/etc/login.defs sets defaults applied when new users are created (e.g., via useradd). It does not usually retroactively change existing accounts.

Key directives (values differ by distro):

Example:

PASS_MAX_DAYS   90
PASS_MIN_DAYS   1
PASS_WARN_AGE   7

This means:

To apply to existing users, use chage (next section), not just login.defs.

Per‑User Password Aging with `chage`

chage (change age) manages password aging on a per‑account basis. It works with data stored in /etc/shadow.

Viewing a user’s password policy

sudo chage -l username

Example output:

Last password change                                    : Aug 20, 2025
Password expires                                        : Nov 18, 2025
Password inactive                                       : never
Account expires                                         : never
Minimum number of days between password change          : 1
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 7

Setting aging values

Common options:

Examples:

Set a 90‑day max, 1‑day min, 7‑day warning:

sudo chage -M 90 -m 1 -W 7 username

Force a user to change password at next login:

sudo chage -d 0 username

Set account to expire on a specific date:

sudo chage -E 2025-12-31 username

This is useful for temporary accounts or contractors.

Password Complexity and Strength (PAM `pam_pwquality` / `pam_cracklib`)

Password complexity is enforced via PAM password modules. On most modern systems:

Rules are configured in:

Example: `pam_pwquality` configuration

Typical pam_pwquality.conf options:

Example configuration:

# /etc/security/pwquality.conf
minlen = 12
dcredit = -1
ucredit = -1
lcredit = -1
ocredit = -1
retry = 3

This means:

These rules are enforced because PAM includes something like:

password    requisite     pam_pwquality.so retry=3

in the appropriate /etc/pam.d/* file (exact file names differ by distro).

Password History (Preventing Reuse)

Password history stops users from cycling back to recent passwords. This is implemented by pam_unix.so with the remember option, or by pam_pwhistory.so on some systems.

Example snippet (RHEL/Fedora style, in /etc/pam.d/system-auth or /etc/pam.d/password-auth):

password    sufficient    pam_unix.so sha512 shadow remember=5

This remembers the last 5 passwords and prevents reuse. You’ll find similar configuration in Debian‑based systems, sometimes via pam_unix or pam_pwhistory.

Common points:

Account Lockout and Failed Login Policies

Lockout policies reduce the risk of brute‑force attacks by:

Implementation differs by distro.

`pam_faillock` (RHEL / Fedora / many modern distros)

Configuration files:

Typical options:

Example faillock.conf:

# /etc/security/faillock.conf
deny = 5
unlock_time = 600
fail_interval = 900

This means:

Managing faillock state

View failures:

sudo faillock

View for a specific user:

sudo faillock --user username

Clear failures (e.g., to unlock before unlock_time):

sudo faillock --user username --reset

Older approaches: `pam_tally2` and `pam_faildelay`

On older systems, pam_tally2 may be used instead of pam_faillock to count failed logins and lock accounts. Another module, pam_faildelay, can introduce a delay after a failed login, slowing brute‑force attempts.

While still seen in older setups, new deployments should favor pam_faillock (or distro‑recommended defaults).

System Password Hashing and Policy Considerations

Although hashing is more of an internal/security topic, it’s directly tied to password policy:

Example PAM line:

password   sufficient    pam_unix.so sha512 shadow

From a policy perspective:

Forcing Password Changes and Locking Passwords

In addition to aging and lockout rules, you’ll sometimes need to:

Force a user to change password

Two common methods:

  1. Set password to expire now:
   sudo chage -d 0 username

User must change password at next login.

  1. With some tools (e.g., passwd):
   sudo passwd -e username

(-e = expire password immediately; availability may vary by distro.)

Lock and unlock passwords

Lock password (disables password-based login but doesn’t remove the account):

sudo passwd -l username

Unlock:

sudo passwd -u username

This is useful for temporarily disabling accounts without deleting them, but note:

Practical Policy Design Tips

When designing policies for real systems:

Verifying Password Policy on Your System

To understand the current policy on a given system:

  1. Check defaults:
    • View /etc/login.defs for aging defaults.
  2. Inspect per‑user settings:
    • sudo chage -l username
  3. Check complexity rules:
    • grep -E 'pwquality|cracklib' /etc/pam.d/* /etc/pam.d/common-password 2>/dev/null
    • View /etc/security/pwquality.conf
  4. Check history and hashing:
    • Look for pam_unix.so lines in /etc/pam.d/* and note options like remember=, sha512.
  5. Inspect lockout rules:
    • Look for pam_faillock.so or pam_tally2 in /etc/pam.d/*
    • View /etc/security/faillock.conf if present.
  6. Test as a non‑privileged user:
    • Try changing to a simple password and see what errors you get; messages often show which rules apply.

Understanding how these pieces fit together lets you implement and audit password policies that match your organization’s security requirements.

Views: 20

Comments

Please login to add a comment.

Don't have an account? Register now!