18.2 Change Passwords and Adjust Password Aging
Key Takeaways
- Set and change passwords with passwd; on RHEL, passwd --stdin is the common non-interactive method as root for exam scripting speed.
- Use chage to view (-l) and set password aging: -m min, -M max, -W warn, -I inactive, -E account expire, -d last change (0 forces change at next login).
- Account expiration (-E) is not the same as password maximum age (-M); read the task language carefully and verify with chage -l.
- Defaults for new accounts often come from PASS_* settings in /etc/login.defs, but named-user tasks are satisfied with chage on that user.
- passwd -e or chage -d 0 expires the password so the user must set a new one at next login—confirm after setting an initial password.
18.2 Change Passwords and Adjust Password Aging
Quick Answer: Set or change passwords with
passwd. Inspect and set aging withchage(-llist,-Mmax days,-mmin days,-Wwarn,-Eexpire date,-Iinactive,-dlast change). Defaults for new accounts often come from/etc/login.defs. Force an immediate password change withchage -d 0 userorpasswd -e user. Verify withsudo chage -l userand the shadow fields.
Why password aging is an EX200 skill
Local accounts are incomplete until authentication policy matches the task. EX200 language looks like:
- “Set the password for user
alice.” - “Password must expire every 90 days.”
- “User must change password at next login.”
- “Account expires on 2026-12-31.”
- “Minimum password lifetime 2 days; warn 7 days before expiry.”
You need both password setting (passwd) and aging controls (chage / related passwd flags). Configuration is stored primarily in /etc/shadow and must persist after reboot (it does—these are file-backed).
passwd: set and manage passwords
Interactive and stdin
sudo passwd alice # prompts twice for new password
echo 'S3curePass!' | sudo passwd --stdin alice # non-interactive (RHEL)
As root, you can set another user’s password without knowing the old one. As an unprivileged user, passwd changes your own password and may enforce quality checks (pam_pwquality and related PAM modules).
passwd # change own password
Useful passwd status flags
| Command | Effect |
|---|---|
passwd -l user | Lock account password |
passwd -u user | Unlock |
passwd -d user | Delete password (empty)—often undesirable |
passwd -e user | Expire password (force change on next login) |
passwd -n MIN user | Minimum days between changes |
passwd -x MAX user | Maximum password lifetime (days) |
passwd -w WARN user | Warn days before expiry |
passwd -i INACT user | Inactive days after password expiry |
passwd -S user | Short status line |
sudo passwd -S alice
sudo passwd -l alice
sudo passwd -u alice
sudo passwd -e alice
RHCSA preference: Many training paths teach chage for aging clarity and passwd for setting the secret. Either aging interface can satisfy tasks if the shadow end state is correct—know chage -l as your primary verification tool.
/etc/shadow fields (mental model)
name:hash:lastchange:min:max:warn:inactive:expire:reserved
| Field | Meaning |
|---|---|
| hash | Password hash, or ! / !! / * for locked/no password |
| lastchange | Days since 1970-01-01 of last password change |
| min | Minimum days before password may be changed again |
| max | Maximum days password remains valid |
| warn | Days before max when user is warned |
| inactive | Days after password expires before account is disabled |
| expire | Account expiration day (absolute), not the same as password max |
sudo grep '^alice:' /etc/shadow
sudo chage -l alice
Prefer chage -l for human-readable output over decoding epoch day numbers by hand under time pressure.
chage: the aging Swiss army knife
List policy
sudo chage -l alice
Example fields you will see:
- Last password change
- Password expires
- Password inactive
- Account expires
- Minimum/Maximum/Warning numbers
Set policy (common exam options)
| Option | Purpose |
|---|---|
-m MIN | Minimum days between password changes |
-M MAX | Maximum password age in days |
-W WARN | Warning days before password expires |
-I INACT | Inactivity days after password expire → disable |
-E DATE | Account expiration (YYYY-MM-DD or days; -E -1 clears) |
-d LAST | Set last password change day (0 = force change next login) |
-l | List |
# Classic corporate-style policy
sudo chage -m 2 -M 90 -W 7 -I 14 alice
sudo chage -l alice
# Account (login) expires on a calendar date
sudo chage -E 2026-12-31 alice
sudo chage -E -1 alice # remove account expiration
# Force password change at next login
sudo chage -d 0 alice
# equivalent idea:
sudo passwd -e alice
sudo chage -l alice
Combining create + password + aging
sudo useradd -m -s /bin/bash alice
echo 'InitialP@ss1' | sudo passwd --stdin alice
sudo chage -d 0 -M 60 -m 1 -W 7 alice
sudo chage -l alice
Set a known password before or as part of the task so the user can log in once and be forced to change it when -d 0 / passwd -e is required.
login.defs defaults (new accounts)
grep -E '^PASS_' /etc/login.defs
Typical keys:
| Key | Role |
|---|---|
PASS_MAX_DAYS | Default max age applied for new entries |
PASS_MIN_DAYS | Default min days |
PASS_MIN_LEN | Historical length hint (PAM may enforce differently) |
PASS_WARN_AGE | Default warning days |
Changing login.defs affects future default application for new users more than rewriting every existing account. If the task names one user, use chage on that user rather than rewriting global defaults unless asked.
# Inspect defaults; avoid casual global edits on the exam
grep -E '^PASS_MAX_DAYS|^PASS_MIN_DAYS|^PASS_WARN_AGE' /etc/login.defs
Account expire vs password expire
These are easy to confuse:
| Mechanism | What it limits | Typical control |
|---|---|---|
Password max age (-M) | How long the password remains valid | chage -M, passwd -x |
Force change (-d 0 / passwd -e) | Password considered immediately expired | next login must set new password |
Account expire (-E) | When the account may no longer log in | calendar end date for the person/contractor |
Lock (passwd -l / usermod -L) | Authentication rejected via locked hash | temporary disable |
A user can have a valid password age but a past account expiration—or the reverse. Read the task words: “password expires every N days” → -M; “account expires on DATE” → -E; “must change password at next login” → -d 0 or passwd -e.
Inactive days (-I)
After the password expires, inactive days may pass before the account is fully disabled for login:
sudo chage -M 90 -I 7 alice
Meaning pattern: password valid 90 days; after it expires, 7 more days of grace (policy-dependent messaging) before inactive disable—confirm with chage -l wording. Use exactly the numbers the task specifies.
Password quality (awareness)
On RHEL, PAM modules (for example pam_pwquality via /etc/security/pwquality.conf) may reject weak passwords for non-root paths. As root setting another user’s password, quality rules are often less strict—but extremely weak passwords can still fail depending on configuration. If passwd rejects a password:
- Choose a longer mixed password.
- Retry.
- Do not disable PAM system-wide on the exam unless a task explicitly redesigns authentication (unlikely for core RHCSA user tasks).
Locking and unlocking (overlap with 18.1)
sudo passwd -l alice
sudo passwd -S alice
sudo passwd -u alice
sudo usermod -L alice
sudo usermod -U alice
Locked accounts show ! or !! prefixes in the shadow hash field. Unlocking restores use of the existing hash when appropriate. Deleting a password with passwd -d can leave an account oddly accessible depending on PAM—prefer lock/expire patterns taught in training over empty passwords.
Verification habits
sudo chage -l alice
sudo passwd -S alice
sudo grep '^alice:' /etc/shadow
# optional: date math sanity—max days and warn match the task
If the task requires next-login change, confirm Last password change is set such that the password is expired (commonly via day 0 semantics shown in chage -l as requiring change).
Exam workflows
Workflow A — Set password only
echo 'CorrectHorseBattery1' | sudo passwd --stdin alice
sudo passwd -S alice
Workflow B — 90-day max, 7-day warn, 2-day min
sudo chage -m 2 -M 90 -W 7 alice
sudo chage -l alice
Workflow C — Must change password at next login
echo 'TempPassw0rd!' | sudo passwd --stdin alice
sudo chage -d 0 alice
# or: sudo passwd -e alice
sudo chage -l alice
Workflow D — Contractor account ends on a date
sudo chage -E 2026-12-31 alice
sudo chage -l alice | grep -i 'Account expires'
Workflow E — Full package for one user
sudo useradd -m -s /bin/bash contractor1
echo 'InitP@ss9' | sudo passwd --stdin contractor1
sudo chage -d 0 -m 1 -M 30 -W 5 -I 3 -E 2026-11-30 contractor1
sudo chage -l contractor1
Common traps
- Setting
PASS_MAX_DAYSin login.defs only and forgettingchageon the named user when the task targets that user. - Mixing up
-Eaccount expire with-Mpassword max days. - Using
chage -d 0without first setting a password—user may be stuck depending on process. - Assuming
passwdinteractive prompts work the same in all non-interactive exam automation—know--stdinon RHEL. - Forgetting
sudosochage -l/ shadow reads fail. - Setting min days higher than max days—nonsensical policy; follow task numbers carefully.
- Locking with
passwd -lwhen the task asked only for aging—do not overshoot. - Not re-running
chage -lafter changes. - Confusing inactive (
-I) with account expire (-E). - Expecting aging to “enable a service”—no systemd step; files alone persist.
Relationship to other sections
- 18.1 Users: accounts must exist before passwords/aging; locks overlap.
- 18.3 Groups: membership does not set passwords.
- 18.4 sudo: password prompts for sudo still use the user’s password policy.
- SSH key auth (security chapter): key login can bypass password entry, but account lock/expire still matter.
- PAM/security: quality and lockouts are related but deeper PAM redesign is beyond basic aging tasks.
Section checkpoint
You should set passwords with passwd (including RHEL --stdin), lock/unlock and expire passwords when required, configure min/max/warn/inactive/account expire with chage, force next-login changes with chage -d 0 or passwd -e, understand /etc/shadow and login.defs defaults, and verify everything with chage -l. That meets the EX200 objective to change passwords and adjust password aging on RHEL 10.
Which command shows the full human-readable password aging policy for user alice?
You must force alice to change her password at next login. Which approach is correct?
A task says alice's password must be changed at least every 90 days and she should be warned 7 days prior. Which chage invocation matches?
What is the difference between chage -E 2026-12-31 alice and chage -M 90 alice?