Skip to main content
RunBook Academy

LinuxIV · Users, Groups and IdentityIdentity

Password policies and account locking

Intermediate⏱ ~10 minbashchagepasswdusermodfaillock

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

Not yet marked complete on this device.

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.

Read-only / Safechage -l
$ chage -l alice
Last 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	: 7

Illustrative output

Configuration changeaging policy
$ sudo chage -M 90 -m 7 -W 14 alice; chage -l alice
Last 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	: 14

Illustrative output

Locking and unlocking

Configuration changepasswd -l
$ sudo passwd -l alice; getent shadow alice
alice:!$y$j9T$...$...:19550:7:90:14:::

Illustrative output

Configuration changepasswd -u
$ sudo passwd -u alice; getent shadow alice
alice:$y$j9T$...$...:19550:7:90:14:::

Illustrative output

Forcing a password reset

Configuration changeforce reset
$ sudo chage -d 0 alice; chage -l alice
Last password change					: password must be changed
Password expires					: never
...

Illustrative output

Account expiration

Configuration changeaccount expiration
$ sudo chage -E 2026-12-31 alice; chage -l alice | grep 'Account expires'
Account expires						: Dec 31, 2026

Illustrative 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).

Read-only / Safepam_faillock config
$ cat /etc/pam.d/common-auth
auth	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 authsucc

Illustrative output

Configuration changefaillock
$ sudo faillock --user alice --reset

Illustrative output

PAM configuration optionEffect
deny=NLock the account after N failed attempts
unlock_time=NAuto-unlock after N seconds (or never)
fail_interval=NThe window in which failed attempts are counted
auditLog every failed attempt to syslog
silentDo not announce failure to the user
  1. **Use pam_faillock, not pam_tally2.** pam_tally2 is deprecated
  2. **Set deny=5 and unlock_time=900.** Five attempts in fifteen minutes is a reasonable baseline. Adjust for your threat model
  3. Pair with a monitoring alert. Lockouts should appear in your SIEM. A lockout that nobody knows about is the same as no lockout
  4. Test the unlock path. Confirm faillock user reset works from your break-glass account before an incident

Knowledge check

Knowledge check · 3 questions

  1. Q1. Which of the following is the strongest way to prevent a user from logging in via any method (password or SSH key)?

  2. Q2. pam_tally2 is the recommended PAM module for failed-login lockout on modern Linux distributions.

  3. Q3. Which of the following are correct password-policy practices? Select all that apply.

Passing score: 75%. Answers are checked in this browser.