Linux Password Aging Policies with chage and passwd
Objective
Password aging controls how long a password stays valid, when users are warned, and what happens when a password or account runs out of time. This guide covers the settings, the commands, and the behaviour that surprises people. By the end, you will know how to:
- Read the password aging fields in
/etc/shadowand view them withchage -landpasswd -S - Set minimum and maximum password age, warning periods, and inactivity limits
- Force a password change at the next login
- Tell the difference between password expiration and account expiration
- Set defaults for new accounts in
/etc/login.defsand/etc/default/useradd - Apply a policy to many users at once, safely
- Apply these skills to LFCS exam tasks and real security work
A password that never changes is a standing risk. If it leaks, it works forever, and if an employee leaves, a forgotten account can stay usable for years. Aging policies add a time dimension to authentication: passwords expire, accounts expire, and unused accounts lock themselves. The tools are small, but the interactions between the settings are where mistakes happen.
The Five Aging Settings
Every account has a handful of time-based settings, all stored in /etc/shadow. Two commands manage them, chage and passwd, and they overlap.
| Setting | What It Controls | chage | passwd | Default for New Users (login.defs) |
|---|---|---|---|---|
| Minimum age | Days that must pass before the user may change the password again | -m |
-n |
PASS_MIN_DAYS (typically 0) |
| Maximum age | Days a password stays valid before it must be changed | -M |
-x |
PASS_MAX_DAYS (typically 99999, effectively never) |
| Warning period | Days before expiry that the user starts seeing warnings at login | -W |
-w |
PASS_WARN_AGE (typically 7) |
| Inactivity period | Days after the password expires before the account is locked | -I |
-i |
Set in /etc/default/useradd (typically disabled) |
| Account expiry date | A calendar date after which the account cannot be used at all | -E |
Not available | None |
Two more actions complete the picture: chage -d 0 or passwd -e forces a password change at the next login, and chage -l shows the current state.
Where the Settings Live: /etc/shadow
The password hash and all aging data sit in /etc/shadow, readable only by root. Dates are stored as a number of days since 1 January 1970, which is why they look cryptic if you read the file directly.
# View one account's shadow entry (requires root)
sudo grep "^policyuser:" /etc/shadow
# Format (9 fields separated by colons):
# policyuser:$6$hash...:20741:7:90:14:30::
# 1 2 3 4 5 6 7 8 9
| Field | Meaning | Example Above |
|---|---|---|
| 1 | Login name | policyuser |
| 2 | Password hash (a leading ! means locked) |
$6$hash... |
| 3 | Date of last password change, in days since 1970-01-01 | 20741 |
| 4 | Minimum age in days | 7 |
| 5 | Maximum age in days | 90 |
| 6 | Warning period in days | 14 |
| 7 | Inactivity period in days after expiry | 30 |
| 8 | Account expiry date, in days since 1970-01-01 (empty means never) | empty |
| 9 | Reserved for future use | empty |
You almost never edit this file directly. Use chage and passwd, which write the fields correctly and handle the date conversion for you.
Viewing Password Aging Information
# Show the full aging details for an account
chage -l policyuser
# Sample output:
# Last password change : Oct 15, 2026
# Password expires : Jan 13, 2027
# Password inactive : Feb 12, 2027
# 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
# A one-line status summary
passwd -S policyuser
# Sample output:
# policyuser PS 2026-10-15 7 90 14 30 (Password set, SHA512 crypt.)
# | | | | | | |
# name status changed min max warn inactive
# status: PS = password set, LK = locked, NP = no password
# Regular users can look at their own aging settings
chage -l
Notice that chage -l turns the stored numbers into real dates. Password inactive is the date the account will lock if the user has not changed the expired password by then.
A Timeline Makes the Settings Click
The settings interact, and a worked example is the fastest way to understand them. Take a password set on 15 October 2026 with a policy of minimum age 7, maximum age 90, warning 14, and inactivity 30 (chage -m 7 -M 90 -W 14 -I 30):
| Day | Date | What Happens |
|---|---|---|
| 0 | 15 Oct 2026 | Password set. The clock starts. |
| 0 to 6 | 15 to 21 Oct | The user cannot change the password again yet (minimum age 7) |
| 7 | 22 Oct 2026 | The user may change the password at any time from here on |
| 76 | 30 Dec 2026 | Warnings begin at login: 14 days before expiry |
| 90 | 13 Jan 2027 | Password expires. The user must set a new one at the next login. |
| 90 to 120 | 13 Jan to 12 Feb | Grace period. The user can still log in, but is forced to change the password. |
| 120 | 12 Feb 2027 | Inactivity period over. The account is locked until an administrator intervenes. |
The account expiry date is a separate, hard stop on top of all of this. If it falls earlier, the account stops working on that date no matter where the password is in its life.
Configuring Password Aging with chage
# Create a test account to work with
useradd -m policyuser
echo "TempPass#2026" | passwd --stdin policyuser # Red Hat family
# On Debian or Ubuntu: set the password interactively with passwd policyuser
# Set the maximum password age to 90 days
chage -M 90 policyuser
# Set the minimum password age to 7 days
chage -m 7 policyuser
# Start warning the user 14 days before expiry
chage -W 14 policyuser
# Lock the account 30 days after the password expires
chage -I 30 policyuser
# Set an account expiry date (format YYYY-MM-DD)
chage -E 2026-12-31 policyuser
# Or set everything in one command
chage -m 7 -M 90 -W 14 -I 30 -E 2026-12-31 policyuser
# Remove the account expiry date
chage -E -1 policyuser
# Disable inactivity locking
chage -I -1 policyuser
# Set the last password change date explicitly
chage -d 2026-10-01 policyuser
# Verify
chage -l policyuser
Configuring Password Aging with passwd
passwd can set most of the same fields, which is why the lab covers both. Learn the mapping, because exam tasks may use either tool.
# Minimum age: 7 days
passwd -n 7 policyuser
# Maximum age: 90 days
passwd -x 90 policyuser
# Warning period: 14 days
passwd -w 14 policyuser
# Inactivity period: 30 days
passwd -i 30 policyuser
# Force a password change at the next login
passwd -e policyuser
# Check the result
passwd -S policyuser
chage -l policyuser
| Goal | chage | passwd |
|---|---|---|
| Minimum age | chage -m 7 user |
passwd -n 7 user |
| Maximum age | chage -M 90 user |
passwd -x 90 user |
| Warning period | chage -W 14 user |
passwd -w 14 user |
| Inactivity period | chage -I 30 user |
passwd -i 30 user |
| Force a change at next login | chage -d 0 user |
passwd -e user |
| Account expiry date | chage -E 2026-12-31 user |
Not available |
| View all settings | chage -l user |
passwd -S user (summary only) |
| Lock or unlock the password | Not available | passwd -l user or passwd -u user |
In practice, chage is the more complete tool because of -E and the readable -l output. passwd adds locking and unlocking.
Forcing a Password Change
Forcing a change at the next login is the standard step after creating an account with a temporary password, or after a suspected compromise.
# Either command forces the user to choose a new password at next login
passwd -e policyuser
chage -d 0 policyuser
# Confirm: "Last password change" now reads "password must be changed"
chage -l policyuser
# A typical new-account sequence
useradd -m newstarter
passwd newstarter # set a temporary password
chage -d 0 newstarter # force a change at first login
chage -M 90 -W 14 newstarter # apply the standard policy
Password Expiration Versus Account Expiration
This is the most common point of confusion. The two sound alike and behave very differently.
| Aspect | Password Expiration | Account Expiration |
|---|---|---|
| Set with | chage -M (maximum age) |
chage -E (a calendar date) |
| What it is based on | Time since the last password change | A fixed date on the calendar |
| What the user experiences | Is forced to choose a new password at login | Cannot log in at all |
| Can the user fix it themselves? | Yes, by changing the password during the grace period | No, only an administrator can change the date |
| Typical use | Routine rotation policy | Contractors, temporary staff, planned end dates |
Ways to Disable an Account, Compared
When someone leaves, choosing the wrong method can leave a way in. These options are not equivalent:
| Method | Command | What It Blocks | Caveat |
|---|---|---|---|
| Lock the password | passwd -l user or usermod -L user |
Password logins | SSH key logins typically still work, because they do not use the password |
| Expire the account | chage -E 0 user |
All logins, including SSH keys | The cleanest way to disable an account while keeping its data |
| Change the shell | usermod -s /sbin/nologin user |
Interactive shells | Does not necessarily stop non-shell services using the account |
| Delete the account | userdel -r user |
Everything | Permanently removes the home directory with -r |
# A safer offboarding sequence: expire the account, lock the password, and keep the data
chage -E 0 departed_user
passwd -l departed_user
# Verify the account is expired and locked
chage -l departed_user
passwd -S departed_user
Combining account expiry with a password lock covers both authentication paths. Also remember to check for authorized SSH keys, scheduled jobs, and any running processes the account owns.
Default Policies for New Accounts
You can set the defaults that every new account inherits, so you do not have to run chage after each useradd.
# View the current defaults
grep -E "^(PASS_MAX_DAYS|PASS_MIN_DAYS|PASS_WARN_AGE)" /etc/login.defs
# Sample output:
# PASS_MAX_DAYS 99999
# PASS_MIN_DAYS 0
# PASS_WARN_AGE 7
# Change the defaults for NEW accounts
sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/' /etc/login.defs
sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 7/' /etc/login.defs
sed -i 's/^PASS_WARN_AGE.*/PASS_WARN_AGE 14/' /etc/login.defs
# Set the default inactivity period for new accounts
useradd -D -f 30
# Review the useradd defaults
useradd -D
# Test with a new account
useradd -m defaulttest
chage -l defaulttest
The change is not retroactive. Editing /etc/login.defs affects accounts created afterward. Existing users keep the values already stored in /etc/shadow, so you must apply the policy to them with chage.
Applying a Policy to Many Users
To bring existing accounts up to a standard, loop over the regular users. Always do a dry run first, and always exclude accounts that should never expire, such as service accounts and emergency access.
# List local regular users (UID 1000 to 59999) and review the list first
awk -F: '$3 >= 1000 && $3 < 60000 {print $1}' /etc/passwd
# Dry run: print what would be changed
for u in $(awk -F: '$3 >= 1000 && $3 < 60000 {print $1}' /etc/passwd); do
echo "chage -m 7 -M 90 -W 14 -I 30 $u"
done
# Apply the policy once the list looks right
for u in $(awk -F: '$3 >= 1000 && $3 < 60000 {print $1}' /etc/passwd); do
chage -m 7 -M 90 -W 14 -I 30 "$u"
done
# Report: who has a password that expires, and when
for u in $(awk -F: '$3 >= 1000 && $3 < 60000 {print $1}' /etc/passwd); do
printf "%-15s %s\n" "$u" "$(chage -l "$u" | grep 'Password expires' | cut -d: -f2)"
done
Designing a Sensible Policy
The commands are the easy part. The harder question is what values to choose, and the guidance has changed over the years.
- Rotation is a tradeoff. Forcing frequent changes can push users toward weak, predictable passwords. Some current guidance, including NIST SP 800-63B, recommends against requiring periodic changes without a reason such as suspected compromise.
- Some compliance regimes still require rotation, so check what your organization is actually obliged to do rather than copying numbers from a tutorial
- Pair aging with the other controls. Aging does not check password strength or prevent reuse. Complexity is handled by
pam_pwquality(configured in/etc/security/pwquality.conf) and history bypam_pwhistory, which are separate topics. - Minimum age stops quick cycling. Without it, a user forced to change their password can immediately change it back. A minimum age of a day or more prevents that.
- Warn early enough to matter. A 7 to 14 day warning gives people a chance to change the password before they are locked out in the middle of work.
- Use account expiry for people who will leave. Contractors and temporary staff should have an end date from the day the account is created.
- Treat service accounts differently. Accounts used by applications should not have passwords that expire unexpectedly. They typically use locked passwords and keys or no-login shells instead.
Troubleshooting
| Symptom | Likely Cause | Fix |
|---|---|---|
| User says "You are required to change your password immediately" | Password expired, or chage -d 0 or passwd -e was used |
Expected behaviour. The user sets a new password at login. |
| User cannot change their password: "You must wait longer to change your password" | Minimum age has not passed | Wait, or an administrator lowers it with chage -m 0 user |
| Account locked with no warning | Inactivity period ended after the password expired, or the account expiry date passed | Check chage -l user. Reset the dates and password. |
| New policy not applied to existing users | /etc/login.defs only affects new accounts |
Apply it with chage to each existing user |
| Service stopped working after a password expired | An application was using an account with an expiring password | Set chage -M -1 user for that account, or move it to key-based authentication |
| Locked account can still log in over SSH | passwd -l blocks password logins, not key logins |
Also set chage -E 0 user or remove the authorized keys |
chage -l shows "password must be changed" |
The last-change date is 0 | The user must log in and set a new password, or an administrator sets a date with chage -d |
Common Mistakes
- Mixing up
-Eand-M.chage -Esets a calendar date when the account dies.chage -Msets how many days a password lasts.- Always run
chage -lafter a change to see both clearly
- Always run
- Expecting
/etc/login.defschanges to update existing users. It does not. Usechageon each account. - Setting the inactivity period to 0 by accident. A value of 0 locks the account the moment the password expires, with no grace period at all. Use
-1to disable it, or a real number of days to allow one. - Applying aging to service accounts. When their password expires, the application breaks, often at a bad time. Exclude them from bulk policy changes.
- Treating
passwd -las a full account disable. It blocks password logins only. Key-based SSH can continue to work. - Forgetting root and emergency accounts. A policy that expires or locks every account can lock you out of the system you are trying to secure. Decide deliberately how those accounts are handled.
- Using the wrong date format for
-E. UseYYYY-MM-DD. A day count or a differently written date may be misread. - Not verifying. Run
chage -landpasswd -Safter every change instead of assuming.
Quick Reference
| Task | Command |
|---|---|
| View aging details | chage -l user |
| View a status summary | passwd -S user |
| Set maximum age to 90 days | chage -M 90 user or passwd -x 90 user |
| Set minimum age to 7 days | chage -m 7 user or passwd -n 7 user |
| Set warning period to 14 days | chage -W 14 user or passwd -w 14 user |
| Lock account 30 days after expiry | chage -I 30 user or passwd -i 30 user |
| Force a change at next login | passwd -e user or chage -d 0 user |
| Set an account expiry date | chage -E 2026-12-31 user |
| Remove account expiry | chage -E -1 user |
| Disable an account immediately | chage -E 0 user |
| Set defaults for new users | PASS_MAX_DAYS, PASS_MIN_DAYS, PASS_WARN_AGE in /etc/login.defs |
| Set the default inactivity for new users | useradd -D -f 30 |
| Set everything at once | chage -m 7 -M 90 -W 14 -I 30 -E 2026-12-31 user |
Password Aging and the LFCS Exam
Managing password aging is part of local user administration, which the LFCS exam covers. Tasks in this area typically ask you to:
- Set a maximum and minimum password age and a warning period for a user
- Force a user to change their password at next login
- Set an account expiry date, or an inactivity period
- Verify the result with
chage -l - Sometimes set default values for new accounts
Exam tasks often use whichever tool the wording suggests, so be comfortable with both chage and passwd, and know which flags map to which settings. As always, confirm the exact objectives against the current LFCS curriculum.
Conclusion
Password aging adds time-based control to authentication. Once you separate the five settings and understand how they run in sequence, the commands are straightforward:
chage -lshows the full picture, andpasswd -Sgives a quick summary-M(maximum),-m(minimum),-W(warning), and-I(inactivity) control the password lifecycle, andpasswdoffers the equivalents-x,-n,-w, and-ichage -d 0orpasswd -eforces a change at next loginchage -Esets a hard account expiry date, which is different from password expirypasswd -llocks the password only. Usechage -E 0to fully disable an account.- Defaults in
/etc/login.defsanduseradd -Daffect only new accounts - Exclude service and emergency accounts from bulk policy, and verify every change with
chage -l
Controlling how passwords age is one half of access control. The other half is controlling what authenticated users are allowed to do with elevated privileges, which is where sudo privilege management comes in next.
Start the Password Aging Policies lab at LinuxCert.Guru → https://linuxcert.guru/lfcs/?name=lfcs-password-aging-policies