User Account Management
Module 3 · Users & Access Management

User Account Management

useradd, usermod, passwd, and the /etc/passwd and /etc/shadow files that actually store account data.

Account Types

TypeUID range (typical)Purpose
Superuser (root)0Unrestricted access to the entire system
System accountsBelow 1000 (varies by distro)Run services/daemons — not meant for interactive login
Regular user accounts1000+Human users logging in and doing work

Where Account Data Lives

FileStores
/etc/passwdAccount metadata: username, UID, GID, home directory, default shell (password field is just a placeholder, x)
/etc/shadowThe actual hashed password and password-aging data, readable only by root
/etc/login.defsSystem-wide defaults for newly created accounts (UID ranges, password aging defaults)
/etc/default/useraddAnother location for useradd defaults — view with useradd -D
/etc/skel/Template files copied into every new user’s home directory at creation time

Modern distributions store the hashed password using SHA-512 by default (you’ll see a $6$ prefix in /etc/shadow) — a major upgrade over the old, now-broken DES and MD5 schemes.

⚠️ Common Pitfall: Never Edit /etc/passwd or /etc/shadow Directly

These files can be hand-edited, but a syntax mistake can lock out every user on the system — including root. Always go through the dedicated tools instead:

  • vipw — safely edit /etc/passwd (locks the file, validates syntax on save)
  • vipw -s — safely edit /etc/shadow
  • pwck — check both files for consistency errors

Creating and Modifying Accounts

TaskCommand
Add a new user (with defaults)useradd username
Add a user with a full name/comment fielduseradd -c "Jane Doe" username
Add a user whose account expires on a specific dateuseradd -e 2026-12-31 username
Set/change a user’s passwordpasswd username
Modify an existing user’s account expiryusermod -e 2026-12-31 username
Attach a real name to an existing accountusermod -c "Jane Doe" username
Change a user’s default shellusermod -s /bin/ksh username
Delete a useruserdel username
Delete a user and their home directoryuserdel -r username

Populate a new account’s home directory from a custom template instead of the default /etc/skel:

useradd -k /path/to/template -m username

Password Aging and Account Locking

TaskCommand
View a user’s password aging detailschage -l username
Change how often a password must be changedchage -M 90 username
Force a password change at next loginchage -d 0 username
Lock a user’s account (disable password login)usermod -L username or passwd -l username
Unlock a user’s accountusermod -U username or passwd -u username

usermod -L and passwd -l both work by prefixing the hash in /etc/shadow with !, which makes it impossible to match — this is a quick lock, distinct from setting an actual account expiration date.


🧠 Knowledge Check

1. Where are user passwords actually stored (hashed), as opposed to general account metadata?

2. You need to edit /etc/passwd by hand. What's the safe way to do it?

3. Which command creates a new user's home directory contents from a custom template directory instead of the default /etc/skel?


What’s Next

Lesson 2 covers the other half of access management: groups, sudo privilege escalation, and the environment files that shape a user’s shell session.