Skip to content
Visual explainer 3h 30m to learn 5 steps

Users, groups & password policy

Create, modify and lock accounts and enforce password aging.

By Invicly Tech, , in Linux Administration (RHCSA-style). About 11 minutes to read.

Topic 9 of 42

In short

Linux identifies users and groups by numeric IDs stored in a few plain-text files. useradd, usermod and groupadd edit them safely, passwd sets passwords, and chage controls password aging. Supplementary groups are how you grant a user access to shared resources.

Explained simply

Every person and every service on a Linux server has an account. To the kernel, an account is just a number called the UID (user ID). The name, such as alice, is only a label that the system looks up in a file. Files are owned by the number, not the name.

Groups collect accounts together. Each user has one primary group, which new files get by default, and can be a member of more supplementary groups. Adding a user to a group is the normal way to give them access to a shared folder, a device or admin rights.

Account details live in plain text files: /etc/passwd lists accounts, /etc/shadow holds the password hashes and password rules, and /etc/group lists groups and their members. You rarely edit these by hand. Tools like useradd, usermod, groupadd and passwd change them safely.

Good account hygiene matters for security. Each person gets their own account, services get accounts that cannot log in, passwords expire on a schedule when policy requires it, and accounts are locked the day someone leaves.

Press Play on a diagram to walk through it one step at a time.

MapAccount database files
Local accounts
  • /etc/passwd
    • name:x:UID:GID:comment:home:shell
    • Readable by everyone
  • /etc/shadow
    • Password hash and aging fields
    • Readable only by root
  • /etc/group
    • group:x:GID:member,member
  • /etc/login.defs
    • Defaults: UID ranges, PASS_MAX_DAYS
  • /etc/skel
    • Files copied into new home directories
CompareThree ways to stop someone logging in
usermod -L (passwd -l)
  • Puts ! in front of the hash
  • Blocks password logins
  • SSH keys may still work
  • Undo with usermod -U
usermod -s /sbin/nologin
  • Blocks interactive shells
  • Account still owns files and runs services
  • Normal for service accounts
  • Undo by setting a real shell
usermod -e 1 (expire)
  • Account expired since 2 Jan 1970
  • PAM refuses every login method
  • Includes SSH keys
  • Undo with usermod -e ''

In depth

Reading /etc/passwd and /etc/shadow line by line

/etc/passwd has seven colon-separated fields: name, x (meaning the password is in shadow), UID, primary GID, a comment such as the full name, the home directory and the login shell. It must be readable by everyone so that ls can turn UIDs into names.

/etc/shadow is readable only by root. Its fields are: name, password hash, date of the last change, minimum days, maximum days, warning days, inactive days, account expiry date and a reserved field. Dates are counted in days since 1 January 1970. The hash starts with its method: $6$ is SHA-512 and $y$ is yescrypt, the default on recent Ubuntu. A hash starting with ! means the password is locked, !! on RHEL means no password was ever set, and * means password login is impossible.

  • getent passwd alice reads the account from every source, including LDAP
  • UID 0 is root; system accounts use low UIDs; people start at 1000
  • pwck checks passwd and shadow for errors

What useradd actually does

useradd reads its defaults from two places. /etc/login.defs sets UID ranges (UID_MIN 1000), password aging defaults, whether to create a home directory and whether to make a private group per user. /etc/default/useradd sets the default shell and the skeleton directory; useradd -D prints them.

With the usual settings, useradd alice picks the next free UID, creates a group alice with the same number, creates /home/alice, copies the files from /etc/skel into it and leaves the password locked until you run passwd. On RHEL the home directory is created automatically. On Ubuntu, plain useradd does not create one unless you add -m and its default shell is /bin/sh, which is why Ubuntu admins often use the friendlier adduser wrapper instead.

Flowuseradd -m -G devs alice
  1. 1
    Read defaults

    /etc/login.defs and /etc/default/useradd

  2. 2
    Pick UID and group

    Next free UID from 1000, private group alice

  3. 3
    Write the files

    passwd, shadow, group, gshadow

  4. 4
    Create the home

    /home/alice with copies of /etc/skel

  5. 5
    Add to devs

    Supplementary group membership

  6. 6
    Password stays locked

    Until you run passwd alice

Group membership and when it takes effect

Group membership is copied into a process when the user logs in, and every child process inherits that list. So after usermod -aG docker alice, her current shell still lacks the new group; id alice shows it, but plain id in her session does not. She must log out and back in, or start a new login with su - alice. newgrp docker opens a new shell with the group active.

usermod -G with a list replaces all supplementary groups, so a missing -a quietly removes the user from wheel or sudo. gpasswd -a alice devs adds one group and gpasswd -d alice devs removes one, which is often clearer.

You cannot delete a group that is still some user's primary group. userdel -r alice removes the account, her home and mail spool, but files elsewhere keep her old UID; find / -nouser finds them before a new user gets that number.

  • id alice shows the stored groups; id shows your current process
  • groups alice lists group names only
  • groupmod -n newname oldname renames a group

Password aging and password quality

chage manages the aging fields in /etc/shadow. -M 90 forces a change every 90 days, -m 1 stops users changing their password back immediately, -W 7 warns seven days before, and -I 14 locks the account if the password stays expired for 14 more days. -E 2026-12-31 expires the whole account on that date, and chage -d 0 alice forces a new password at the next login.

PASS_MAX_DAYS and friends in /etc/login.defs are only copied to accounts when they are created; changing them later does not touch existing users. Password strength (length, character classes, dictionary words) is not set in login.defs at all. It comes from the PAM module pam_pwquality, configured in /etc/security/pwquality.conf with settings such as minlen = 12.

FlowPassword aging timeline with chage -m 1 -M 90 -W 7 -I 14
  1. 1
    Day 0: password set

    Stored as the last change date

  2. 2
    Day 1

    User may change it again

  3. 3
    Day 83

    Login shows a warning

  4. 4
    Day 90

    Expired: must change at login

  5. 5
    Day 104

    Inactive period over: account locked

Learn it in 5 short steps

About 40m each. Track them with a timer in your plan.

  1. 1
    Create users with useradd and passwd~40m
  2. 2
    Manage groups and supplementary membership~40m
  3. 3
    Read /etc/passwd, /etc/shadow, /etc/group~40m
  4. 4
    Set password aging with chage~40m
  5. 5
    Set defaults in /etc/login.defs~40m

Key points

  • usermod -aG group user adds a supplementary group; forgetting -a replaces all groups.
  • Regular users start at UID 1000; lower IDs are system accounts.
  • chage -M 90 sets maximum password age; chage -l shows the policy.
  • usermod -L locks an account and -s /sbin/nologin blocks interactive logins.
  • Group changes apply at the next login; check with id.

Key terms

Tap a card to flip it. 0/5 known

Examples

bash
sudo groupadd -g 3000 sysadmins
sudo useradd -m -G sysadmins -c "Natasha R" natasha
echo 'natasha:Str0ng!Pass' | sudo chpasswd
sudo useradd -s /sbin/nologin svc-backup
sudo usermod -aG wheel natasha
sudo chage -M 90 -W 7 natasha && sudo chage -l natasha
id natasha

Typical RHCSA account tasks.

Onboard a contractor with an end date

A contractor, ravi, starts today and leaves at the end of the year. He needs to be in group devs and must pick his own password at first login. Step 1: create the account with a home, a full name, the extra group and an expiry date. Step 2: set a temporary password. Step 3: force a change at the next login and set a 90-day maximum. Step 4: check the result with chage -l and id.

bash
sudo useradd -m -c "Ravi K (contractor)" -G devs -e 2026-12-31 ravi
echo 'ravi:Temp-Pass-2026!' | sudo chpasswd
sudo chage -d 0 -M 90 -W 7 ravi
sudo chage -l ravi
# Password must be changed / Account expires : Dec 31, 2026
id ravi

Offboard a leaver properly

Mark leaves the company today. Step 1: expire and lock the account so no method works, SSH keys included. Step 2: end his running sessions and processes. Step 3: archive his home directory for the retention period. Step 4: remove the account. Step 5: find files elsewhere that still carry his old UID, so you can reassign them before that UID is reused.

bash
sudo usermod -L -e 1 mark
sudo loginctl terminate-user mark
sudo pkill -KILL -u mark
sudo tar -czf /root/archive/mark-home-$(date +%F).tgz -C /home mark
sudo userdel -r mark
sudo find / -xdev -nouser -ls 2>/dev/null | head

Quick reference

  • usermod -aG grp user adds a group; without -a it replaces all supplementary groups
  • gpasswd -d user grp removes a user from one group
  • useradd -D shows defaults; /etc/login.defs holds UID ranges and aging defaults
  • chage -d 0 user forces a password change at next login
  • chage -E 2026-12-31 user expires the account on that date
  • usermod -L only locks the password; usermod -e 1 blocks every login method
  • getent group devs shows a group and its members from all sources
  • Password strength rules live in /etc/security/pwquality.conf, not login.defs

Common mistakes

  • usermod -G without -a, which removes the user from every other group.
  • Editing /etc/passwd or /etc/shadow by hand instead of using the tools or vipw.

Quick quiz

Pick an answer to see if you're right and why.

Question 1

1You ran usermod -G devs alice. What happened to her other supplementary groups?

Question 2

2A user was added to the docker group, but docker commands still fail in her open terminal. Why?

Question 3

3In /etc/shadow, what does a password field starting with ! mean?

Question 4

4You change PASS_MAX_DAYS to 60 in /etc/login.defs. Which accounts are affected?

Question 5

5Which command blocks all logins for an account, including SSH key logins?

0/5 answered

Practice exercises

Try each one yourself first. Use the hint if you get stuck, then compare with the solution.

  1. Exercise 1easy

    Create a group ops with GID 4000 and a user sam whose supplementary group is ops. Show his UID, GID and groups.

  2. Exercise 2medium

    Make every new account get a 60-day maximum password age, a 7-day warning, and a minimum length of 12 characters. Then apply the same aging to the existing user sam.

  3. Exercise 3hard

    Create a service account bkpsvc with no home directory, no login shell, a fixed UID of 990 and its own group, then prove nobody can get a shell as it.

Check yourself

Answer in your head, reveal, then be honest with yourself.

Feel confident about this topic?

Frequently asked questions

What is the difference between useradd and adduser?
useradd is the low-level tool on every distribution. On Ubuntu and Debian, adduser is a friendlier script that asks questions and creates the home directory; on RHEL, adduser is simply a link to useradd.
Why does /etc/passwd show x instead of a password?
The x means the real password hash is in /etc/shadow, which only root can read. Long ago hashes were in /etc/passwd itself, readable by everyone.
How do I see which groups a user is in?
Run id username or groups username. For the groups of your own current session, run id with no argument.
Can two users have the same UID?
The tools can force it, but the kernel then treats them as the same user for every file and process. Avoid it; give each account its own UID.

Go deeper

ShareXLinkedInWhatsApp