Skip to main content
Users forget passwords, accounts can be compromised, and sometimes access persists for people who should no longer have it. Without proper password and account lifecycle management, systems become vulnerable. This guide explains how Linux stores passwords, how to enforce password policies, how to set expiration rules, and how to lock or unlock accounts when needed. You’ll learn practical commands and where default settings come from so you can implement repeatable, auditable policies. What you’ll learn:
  • How Linux stores password data
  • Where default password policies are defined
  • How to inspect and change password aging for existing accounts
  • How to set account expiration and force password resets

How Linux stores passwords

  • Password hashes are stored in /etc/shadow. These are hashed values — not plaintext — to protect confidentiality.
  • Only privileged users (typically root) can read /etc/shadow.
The /etc/passwd file contains account metadata (username, UID, GID, shell, home directory) but not the password hashes; the hashes live in /etc/shadow, which has restricted permissions.

Default password policy for new accounts

When you create a new user, Linux assigns default password aging values from /etc/login.defs. This file controls:
  • Maximum password age (PASS_MAX_DAYS)
  • Minimum days between password changes (PASS_MIN_DAYS)
  • Minimum password length (PASS_MIN_LEN)
  • Warning period before password expiration (PASS_WARN_AGE)
Changing these values in /etc/login.defs affects users created after the change.

Managing existing accounts with chage

Use chage to view and modify password aging and account expiration for existing users. chage supports both non-interactive flags and an interactive prompt. Common chage usages are summarized below. Note: Regular users can change their own password with passwd. Only root can change other users’ passwords or change other users’ aging settings.

Quick reference: chage examples and expected output

Create user1, set a password, then configure aging:
Force a password change on next login and set aging policy:
Set an account expiration date:

Interactive mode example

chage without flags enters interactive mode and prompts for values. This is useful for manual auditing and ad-hoc policy changes.

Where do the default values come from?

New-user defaults are taken from /etc/login.defs. Look for these parameters:
If you change PASS_MAX_DAYS to 30 in /etc/login.defs, any users created afterwards will inherit MAX_DAYS=30. Example: create user3 after changing defaults
This demonstrates that PASS_MAX_DAYS = 30 in /etc/login.defs was applied to the new account.

Best practices and operational notes

  • Only privileged users (root) can read /etc/shadow and modify other users’ password settings. Use least privilege for management tasks.
  • Use chage -l <user> regularly to audit user password aging configuration. Automate checks where possible.
  • Update /etc/login.defs to enforce default policies for accounts created in the future, and apply chage to existing accounts to make policies consistent across your environment.
Additional tips:
  • Require complex passwords and enforce minimum length (PASS_MIN_LEN) in /etc/login.defs or via PAM modules.
  • Combine expiration policies with account lockout rules from PAM (e.g., pam_faillock) to reduce brute-force risk.
  • Document policy changes and keep a change log for compliance requirements.

Recap

  • Password hashes are stored in /etc/shadow with restricted access.
  • Default password aging for new users is defined in /etc/login.defs.
  • Use chage to modify expiration rules and force password resets for existing users.
  • Use passwd for password changes; regular users can change their own password, while root can change any account’s password.
  • Combine /etc/login.defs, chage, PAM configuration, and auditing to enforce password policies and manage account lifecycle effectively.

With this knowledge, you should be comfortable managing password policies, expiration, and account lifecycle for Linux users.

Watch Video

Practice Lab