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
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 option | Purpose |
|---|---|
-m | Create the user’s home directory |
-s /bin/bash | Set the login shell |
-g groupname | Set the primary group |
-G group1,group2 | Add supplementary groups |
-u 1050 | Force 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 lab22sudo passwd lab22Untilpasswdsucceeds, password-based login forlab22fails 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 piece | Passwd field |
|---|---|
maya | 1 — username |
(system writes x) | 2 — placeholder → /etc/shadow |
-u 1105 | 3 — UID |
-g studio (GID 1600) | 4 — primary GID |
-c "Maya Lopez" | 5 — GECOS |
-m → /home/maya | 6 — home |
-s /bin/bash | 7 — shell |
-G designers,video | Not 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
| Invocation | Who it affects |
|---|---|
passwd | Changes your password |
sudo passwd alice | Root (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.
| Command | Creates |
|---|---|
useradd | User account (UID) |
groupadd | Group (GID) |
passwd | Password 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/.bashrcexists and you runsudo useradd -m demo, expect/home/demo/.bashrcowned bydemo. Missing starters → check skel and whether-mwas used. A classREADMEplaced 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 account | Usual UID range (common pattern) |
|---|---|
| Root | 0 |
| System / service | Low range (often 1–999) |
| Regular human users | High 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
- Human account (home + shell) vs system-style (often no login shell).
groupaddfirst if you need a project GID.useradd -m ...with primary/supplementary groups as required.passwd, then verify withid 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
-mwhen 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.
Which directory provides the default files copied into a newly created home directory when useradd creates that home?
You run sudo useradd -m jordan but do not run passwd. What is the most accurate result?
Which command creates a new group entry (a new GID) on the system?
Why do administrators care about the numeric UID when recreating a deleted username?