LinuxIV · Users, Groups and IdentityIdentity
Password policies and account locking
What you'll learn
- Set password aging policies with chage
- Distinguish password lock from account expiration
- Configure lockout after failed attempts via PAM
- Audit locked and expired accounts
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
Production identity has three time dimensions: how often the
password must change, when the account itself expires, and how
the system responds to failed login attempts. The tools are
chage, passwd, and PAM configuration.
chage — password aging
chage controls the password aging fields in /etc/shadow.
$ chage -l aliceLast password change : Aug 09, 2026
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7Illustrative output
$ sudo chage -M 90 -m 7 -W 14 alice; chage -l aliceLast password change : Aug 09, 2026
Password expires : Nov 07, 2026
Password inactive : never
Account expires : never
Minimum number of days between password change : 7
Maximum number of days between password change : 90
Number of days of warning before password expires : 14Illustrative output
Locking and unlocking
$ sudo passwd -l alice; getent shadow alicealice:!$y$j9T$...$...:19550:7:90:14:::Illustrative output
$ sudo passwd -u alice; getent shadow alicealice:$y$j9T$...$...:19550:7:90:14:::Illustrative output
Forcing a password reset
$ sudo chage -d 0 alice; chage -l aliceLast password change : password must be changed
Password expires : never
...Illustrative output
Account expiration
$ sudo chage -E 2026-12-31 alice; chage -l alice | grep 'Account expires'Account expires : Dec 31, 2026Illustrative output
Failed-login lockout via PAM
PAM modules enforce login attempt policies. The two relevant ones
are pam_faillock (modern, recommended) and pam_tally2 (legacy).
$ cat /etc/pam.d/common-authauth required pam_faillock.so preauth
auth [success=1 default=bad] pam_unix.so
auth [default=die] pam_faillock.so authfail
auth sufficient pam_faillock.so authsuccIllustrative output
$ sudo faillock --user alice --resetIllustrative output
| PAM configuration option | Effect |
|---|---|
deny=N | Lock the account after N failed attempts |
unlock_time=N | Auto-unlock after N seconds (or never) |
fail_interval=N | The window in which failed attempts are counted |
audit | Log every failed attempt to syslog |
silent | Do not announce failure to the user |
- **Use
pam_faillock, notpam_tally2.** pam_tally2 is deprecated - **Set
deny=5andunlock_time=900.** Five attempts in fifteen minutes is a reasonable baseline. Adjust for your threat model - Pair with a monitoring alert. Lockouts should appear in your SIEM. A lockout that nobody knows about is the same as no lockout
- Test the unlock path. Confirm faillock user reset works from your break-glass account before an incident
Knowledge check
Knowledge check · 3 questions
Q1. Which of the following is the strongest way to prevent a user from logging in via any method (password or SSH key)?
Q2. pam_tally2 is the recommended PAM module for failed-login lockout on modern Linux distributions.
Q3. Which of the following are correct password-policy practices? Select all that apply.
Passing score: 75%. Answers are checked in this browser.