5.2 Creating Users and Groups

Key Takeaways

  • useradd creates accounts; groupadd creates groups; passwd sets or changes a user’s password
  • New home directories are often seeded from files in /etc/skel so every user starts with the same starter configs
  • UIDs uniquely identify users; GIDs identify groups—names are labels mapped to those numbers
  • Human users typically receive UIDs from a high range (commonly starting at 1000); system accounts use lower UIDs
  • After creating an account, set a password with passwd before expecting interactive password logins
Last updated: July 2026

5.2 Creating Users and Groups

Once you can identify account types and the /etc databases, the next Essentials skill is creating users and groups safely. You do not need every obscure useradd flag, but you must know the core commands, what a new account needs before login works, and how UID/GID numbering fits the picture.

Creating a user with useradd

The useradd command adds a new entry to the account databases (and, depending on options and distro defaults, may create a home directory).

sudo useradd -m -s /bin/bash maya
sudo passwd maya
Common optionPurpose
-mCreate the user’s home directory
-s /bin/bashSet the login shell
-g groupnameSet the primary group
-G group1,group2Add supplementary groups
-u 1050Force a specific UID (use carefully)
-c "Maya Lopez"Set the GECOS/comment field

Distro defaults differ: some systems create a matching private group (UID=GID naming), others place new users in a shared users group. For the exam, focus on useradd creates the account record, and -m ensures a home directory. Without -m, you may get a passwd entry but no /home/username until you create it yourself.

Worked example: An instructor adds a lab account: sudo useradd -m -s /bin/bash lab22 sudo passwd lab22 Until passwd succeeds, password-based login for lab22 fails even though the account exists in /etc/passwd.

Worked walkthrough: useradd/etc/passwd fields

Map each flag to the colon-separated passwd line so you can predict the result:

sudo groupadd -g 1600 studio
sudo useradd -m -u 1105 -g studio -G designers,video -c "Maya Lopez" -s /bin/bash maya

Resulting line (field order):

maya:x:1105:1600:Maya Lopez:/home/maya:/bin/bash

useradd piecePasswd field
maya1 — username
(system writes x)2 — placeholder → /etc/shadow
-u 11053 — UID
-g studio (GID 1600)4 — primary GID
-c "Maya Lopez"5 — GECOS
-m/home/maya6 — home
-s /bin/bash7 — shell
-G designers,videoNot in passwd — supplementary groups in /etc/group

Verify with id maya (uid, gid, groups) and ls -ld /home/maya. If -G was omitted, only the primary group appears. If -m was omitted, the home directory may be missing even when field 6 names a path. Run getent passwd maya as another quick confirmation that the account record landed.

Setting passwords with passwd

InvocationWho it affects
passwdChanges your password
sudo passwd aliceRoot (via sudo) sets alice’s password

passwd updates /etc/shadow. Essentials cares about the workflow: create account → set password → user can log in. Password management is separate from merely adding a username.

Creating groups with groupadd

sudo groupadd designers
sudo useradd -m -s /bin/bash sam -G designers

groupadd creates a new GID in /etc/group. Attach users with useradd -G or later membership changes (usermod -aG on many systems). Shared project directories often rely on a common group so members collaborate without sharing one login.

CommandCreates
useraddUser account (UID)
groupaddGroup (GID)
passwdPassword hash / credentials

/etc/skel — the new-home template

When useradd -m creates a home, it typically copies files from /etc/skel (for example .bashrc, .profile) into /home/username/.

Worked check: If /etc/skel/.bashrc exists and you run sudo useradd -m demo, expect /home/demo/.bashrc owned by demo. Missing starters → check skel and whether -m was used. A class README placed in skel is copied to every later new home.

UIDs and GIDs: numbers are the real identity

Linux stores ownership as numbers. Recreating username alice with a different UID leaves old files tied to the previous number (or a numeric owner if the name mapping is gone).

Kind of accountUsual UID range (common pattern)
Root0
System / serviceLow range (often 1–999)
Regular human usersHigh range (often 1000+)

Human users are not UID 0 and usually sit above the system range; exact UID_MIN values vary by distro.

Practical creation checklist

  1. Human account (home + shell) vs system-style (often no login shell).
  2. groupadd first if you need a project GID.
  3. useradd -m ... with primary/supplementary groups as required.
  4. passwd, then verify with id username.
sudo groupadd projectx
sudo useradd -m -s /bin/bash -G projectx kai
sudo passwd kai
id kai

Common mistakes to avoid on the exam

  • Creating a user but forgetting passwd.
  • Forgetting -m when a home is expected.
  • Confusing /etc/skel (template) with /etc/shadow (hashes).
  • Assuming the username string alone owns files forever—UID is what the filesystem stores.

Topic 5.2 creates identities; Topic 5.3 applies them with chmod/chown. A wrong UID at creation becomes a wrong owner later.

Test Your Knowledge

Which directory provides the default files copied into a newly created home directory when useradd creates that home?

A
B
C
D
Test Your Knowledge

You run sudo useradd -m jordan but do not run passwd. What is the most accurate result?

A
B
C
D
Test Your Knowledge

Which command creates a new group entry (a new GID) on the system?

A
B
C
D
Test Your Knowledge

Why do administrators care about the numeric UID when recreating a deleted username?

A
B
C
D