Advanced
Searching inHow-to guides
How to search
  • Type the task in your own words (find port, open firewall, disk full) or paste an error message in quotes.
  • Choose "Quick answer" to see only the commands, or an area to stay in one field.
  • "two words" finds the exact phrase.
  • Plain words find names, texts and examples.
  • ↑ ↓ to move · Enter to open · Esc to close · / to search
Try:

How-to 116Security · Users

How to set password rules and expiry

Audits (ISO 27001, PCI, internal policies) ask: how long must passwords be, how often do they expire, what happens after wrong tries? On Linux three parts answer this: pwquality (strength), chage / login.defs (age), and faillock (lockout after failed logins). This how-to sets all three on RHEL and Ubuntu and checks them.

  • 5 Lessons
  • 4 Commands

$ run as a normal user# run as root (or with sudo)

116.1

The quick answer

/etc/security/pwquality.conf.d/10-policy.conf
minlen = 14
minclass = 3
dictcheck = 1
chage -M 90 -m 1 -W 14 alice
chage -l alice
authselect enable-feature with-faillock
faillock --user alice

authselect is for RHEL; on Ubuntu install libpam-pwquality (strength) and configure pam_faillock (lockout).

Commands in this lesson

116.2

Step by step

  1. Strength — pwquality checks new passwords:
SettingMeans
minlen = 14At least 14 characters.
minclass = 3At least 3 of: lower, upper, digit, other.
dictcheck = 1Reject dictionary words.
usercheck = 1Reject passwords with the user name.
enforce_for_rootAlso for root (otherwise root gets only a warning).
  1. Age for existing users with chage:
chage -M 90 -m 1 -W 14 alice
chage -l alice
Maximum number of days between password change          : 90
Number of days of warning before password expires       : 14

-M max days, -m min days (stops changing back at once), -W warning days. chage -d 0 alice forces a change at the next login.

  1. Defaults for new users in /etc/login.defs (only users created after the change):
/etc/login.defs (part)
PASS_MAX_DAYS   90
PASS_MIN_DAYS   1
PASS_WARN_AGE   14
  1. Lockout after failed logins (faillock):
/etc/security/faillock.conf
deny = 5
unlock_time = 900
fail_interval = 900
authselect enable-feature with-faillock
faillock --user alice
faillock --user alice --reset

5 failures in 15 minutes lock the account for 15 minutes; --reset unlocks it at once.

  1. Modern advice to discuss with the auditor: current NIST guidance prefers long passwords/passphrases, a check against leaked passwords, MFA, and no forced regular expiry (only change after a suspected leak). Many company policies still ask for expiry — follow your policy, but long + MFA matters most. For servers, the best rule is: no passwords for SSH at all (keys only).

Commands in this lesson

116.3

Check that it worked

passwd
New password: short
BAD PASSWORD: The password is shorter than 14 characters
chage -l alice | head -4
faillock --user alice

A weak password is refused, the age rules are set, and failed logins are counted.

116.4

Common problems

ProblemCauseFix
New rules do not apply to old userslogin.defs affects only new users.Use chage for existing users (Ansible for many).
Root can still set weak passwordspwquality only warns for root.enforce_for_root.
Changes to PAM files are overwritten (RHEL)authselect manages PAM.Use authselect features / custom profiles, not manual edits.
A user is locked and can not workfaillock lockout.faillock --user USER --reset; check what made the failures (a script with an old password?).
Service accounts expire and jobs stopExpiry set on service accounts.chage -M -1 svcuser (and no password login for them at all).
Ubuntu: rules have no effectlibpam-pwquality not installed.apt-get install libpam-pwquality.

Commands in this lesson

116.5

Go further

1Why do changes in /etc/login.defs not affect existing users?

They are defaults for new accounts; existing users need chage.

2Which tool locks an account after too many failed logins?

pam_faillock (/etc/security/faillock.conf, check with faillock --user).

All commands in this chapter