Linux Users & Groups: The Complete Visual Guide

Learn to create, manage, and understand Linux users and groups. Master useradd, groupadd, usermod, and the /etc/passwd file with real commands and visual guides.

Diagram showing Linux users and groups as an org chart with /etc/passwd and /etc/group files
📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free

You share your Linux system with invisible people you never invited.

Run this right now:

cat /etc/passwd | wc -l

Got 30+? Every line is a user. Most of them are services — www-data (your web server), mysql (your database), syslog (your logging system). They all had accounts created automatically.

Understanding these users is Day 1 Linux SysAdmin work.

The Two Key Files

Everything about users and groups on Linux lives in four files:

FileContainsReadable by
/etc/passwdAll users (no passwords)Everyone
/etc/shadowHashed passwordsRoot only
/etc/groupAll groupsEveryone
/etc/gshadowGroup passwords (rare)Root only
Where Did the Password Go?

Historically, /etc/passwd stored hashed passwords in the second field. But since everyone can read /etc/passwd, it became a security risk.

In the 1980s, “shadow passwords” moved the hashes to /etc/shadow (root-only). Now /etc/passwd just has an x in the password field — meaning “look in shadow”.


Decoding /etc/passwd

Every line in /etc/passwd has 7 fields separated by colons (:):

Annotated /etc/passwd line: shekhar:x:1001:1001:Shekhar Kumar:/home/shekhar:/bin/bash — with each field labeled
Every line in /etc/passwd has 7 fields. Each field has a specific meaning. Understanding this gives you full insight into any Linux user.
shekhar : x : 1001 : 1001 : Shekhar Kumar : /home/shekhar : /bin/bash
   1       2    3      4          5                6               7
FieldValueMeaning
1shekharUsername (what you type at login)
2xPassword is in /etc/shadow (always x on modern Linux)
31001UID — User ID number (OS uses this, not the name)
41001Primary GID — the user’s main group
5Shekhar KumarGECOS — display name / comment
6/home/shekharHome directory
7/bin/bashLogin shell (/usr/sbin/nologin = service account)
Service Account Pattern

Look for users with field 7 = /usr/sbin/nologin or /bin/false.

These are service accounts — they run services but can’t be logged into interactively. www-data, mysql, syslog, daemon are all service accounts. This is intentional security design.


The User Org Chart

Org chart showing root at top, then system accounts (www-data, mysql, syslog) and regular users (shekhar, alice), each with their UID ranges
How Linux organizes user types: System accounts (UID 0-999) run services, regular users (UID 1000+) are real people with home directories and login shells.

UID Ranges

UID RangeTypeExamples
0Superuserroot only, always
1 – 999System accountsdaemon, www-data, mysql, syslog
1000+Regular human usersshekhar, alice, bob
65534nobody userUltra-minimal permissions for mapped-nobody scenarios

Managing Users

Creating a User

useradd vs adduser — Which to Use?
  • useradd: Low-level C program. Available on all Linux distros. No prompts. Requires flags for everything.
  • adduser: Higher-level Perl script (Debian/Ubuntu). Interactive. Creates home dir, asks for password automatically.

Recommendation: Use adduser on Ubuntu/Debian for humans. Use useradd in scripts and on other distros.

The simple way (Ubuntu/Debian):

sudo adduser alice

Create a new user 'alice' with home directory, interactive password setup, and default shell

beginner
  • adduser creates /home/alice automatically
  • It will prompt for a password and GECOS info
  • It creates a primary group 'alice' automatically
  • Only available on Debian/Ubuntu. Use 'useradd' on RHEL/CentOS.

The full control way (all distros):

sudo useradd -m -s /bin/bash -c 'Alice Smith' alice

Create user 'alice' with home dir (-m), bash shell (-s), and display name (-c)

beginner
  • -m = create home directory at /home/alice
  • -s /bin/bash = set login shell to bash
  • -c 'Alice Smith' = GECOS/comment field (display name)
  • After this, set password: sudo passwd alice

Set or change a password:

sudo passwd alice

Set or change the password for user 'alice'

beginner
  • Without sudo, 'passwd' changes YOUR own password
  • With sudo, 'passwd alice' changes alice's password
  • Password is stored hashed in /etc/shadow — never in plain text

Modifying Users

Add user to a group (the most common operation):

sudo usermod -aG docker alice

Add alice to the 'docker' group (without removing her from existing groups)

beginner
  • -a = APPEND (add to group without removing from others)
  • -G = specify supplementary group(s)
  • CRITICAL: always use -a with -G. Without -a, alice loses all other group memberships!
  • Changes take effect at alice's NEXT login
  • Common groups to add users to: sudo, docker, www-data, adm
The -a Flag Is Not Optional

sudo usermod -G docker alice WITHOUT -a will remove alice from ALL other groups and only put her in docker.

Always: usermod -aG (a for append, G for group). Never: usermod -G alone.

Change a user’s shell:

sudo usermod -s /bin/zsh alice

Change alice's login shell to zsh

beginner
  • Valid shells are listed in /etc/shells
  • Use /usr/sbin/nologin to disable a service account's login

Lock and unlock a user:

sudo usermod -L alice

Lock alice's account (prevents login, doesn't delete anything)

beginner
  • -L = lock (adds ! to the password hash in /etc/shadow)
  • -U = unlock
  • Useful for temporarily disabling ex-employees without deleting their data
  • 'passwd -l alice' does the same thing

Deleting a User

sudo userdel -r alice

Delete user 'alice' AND her home directory and mail spool (-r)

beginner
  • -r = remove home directory and mail spool
  • Without -r: user is deleted but /home/alice remains (orphaned files)
  • Orphaned files keep alice's UID number but no name — show up as UID number in 'ls -la'
  • Always double-check: does alice have data you need to backup first?

Managing Groups

Creating Groups

sudo groupadd developers

Create a new group called 'developers'

beginner
  • Group is created in /etc/group
  • New group starts empty — no members
  • Use usermod -aG to add users after

Adding Users to Groups

sudo gpasswd -a alice developers

Add alice to the 'developers' group (alternative to usermod -aG)

beginner
  • gpasswd -a = add user to group
  • gpasswd -d = remove user from group
  • Either gpasswd or usermod -aG works — both are correct

Viewing Group Membership

getent group developers

Show all members of the 'developers' group

beginner
  • Output format: group_name:password:GID:member1,member2,member3
  • getent reads from /etc/group (and potentially LDAP/NIS in enterprise)
  • 'groups alice' shows all groups alice belongs to

Hands-On Challenge

Complete this sequence on your Linux machine:

  1. Create a new user devops with home directory and bash shell
  2. Create a group engineers
  3. Add devops to the engineers group (using usermod -aG)
  4. Verify with id devops — you should see engineers in the groups list
  5. Lock the account with usermod -L devops
  6. Verify the lock: sudo passwd -S devops (should show L status)
  7. Bonus: Look at /etc/shadow as root — find the ! before devops’s password hash that indicates the lock

Key Takeaways

  1. /etc/passwd has 7 fields — learn to read each one. The login shell field immediately tells you if it’s a service account or human account.
  2. UIDs are what matter — the OS uses numbers, not names. 1000+ = human, 1-999 = service, 0 = root.
  3. usermod -aG — the -a is MANDATORY when adding groups. Forget it and you wipe all existing group memberships.
  4. adduser vs useraddadduser is friendlier and Debian/Ubuntu only. useradd is universal but requires manual flags.
  5. Service accounts (www-data, mysql) can’t log in interactively — this is by design for security. Never give them a real shell.
  6. Group membership changes → user must log out and back in for them to take effect.
You Now Know

How to read /etc/passwd, create and manage real users and service accounts, add users to groups safely, and understand the difference between UIDs 0-999 (system) and 1000+ (human). You are now a functioning Linux user manager.

Next Steps in This Series

🧠

Test Your Knowledge

Take a quick 3-question quiz to check your understanding.

📧

Get weekly IT guides

Join 5,000+ IT professionals

Subscribe Free
Type to start searching...