Managing Users and Groups
Quick answer
Account creation, membership changes and removal are administrative operations with persistent effects. Plan the desired identity, home and groups before changing anything, and practice only inside a dedicated disposable virtual machine.
Prepare the practice environment
Use the chapter fixture described in lab-fixtures/users/README.md. Run setup as a normal user in a disposable Linux environment, enter the printed directory, check pwd, and run export LC_ALL=C; umask 022. Every local example assumes a fresh fixture; examples explicitly marked VM ONLY require an authorized snapshot-backed VM and must not be run in the ordinary fixture. Commands omit the terminal prompt; outputs below are not commands.
How it works
On Debian/Ubuntu, shadow utilities provide useradd, usermod, userdel, groupadd, passwd and chage. useradd -m requests a home directory; -g selects an existing primary group. usermod -aG appends supplementary groups, whereas -G without -a replaces their list. New membership normally needs a new session. passwd changes authentication secrets through policy; chage -l displays aging data for an authorized local account. Deleting an account does not necessarily remove all files it owns; userdel -r can remove the home and mail spool, so do not use it as a default. Check UID reuse risks, processes and ownership before deprovisioning. Snapshot rollback is the cleanup in this lab.
If a fictional account belongs to supplementary groups audit and reports, appending backup preserves both existing memberships; replacing the list with only backup removes the other two. The VM example uses && so the account creation step runs only after successful group creation. If group creation succeeds but account creation fails, that group may remain. Stop and inspect the state before retrying; use the approved snapshot rollback rather than deleting guessed names.
Try the examples
awk -F: '$1 == "bmreader" {printf "planned=%s uid=%s gid=%s\n", $1,$3,$4}' passwd.sampleRead the proposed identity from the fixture; real UID allocation is left to the VM administrator.
Expected stdout:
planned=bmreader uid=21001 gid=21010# VM ONLY: after snapshot and instructor approval# Check that both names and the proposed home do not exist.if getent passwd bm9learner || getent group bm9lab || test -e /home/bm9learner || test -L /home/bm9learner; then printf 'Name or home already exists; stop.\n'else sudo groupadd bm9lab && sudo useradd -m -d /home/bm9learner -g bm9lab -s /bin/bash bm9learner && id bm9learnerfiOnly run on a snapshot-backed isolated VM with local account databases, authorization and no real data. Inspect each result; stop on error and revert the snapshot. No password is set by this example.
Manual example; not executed locally. Follow its stated environment restrictions.
# VM ONLY: use the account created aboveid bm9learnersudo chage -l bm9learner# Review ownership, active processes and retention with instructor.# Reset the VM snapshot instead of deleting a live account.The chage output depends on local policy. For removal, review the account and retention plan; the reference explains userdel but this lab resets the VM instead.
Manual example; not executed locally. Follow its stated environment restrictions.
Common mistakes
Never use real usernames or modify production account databases in this lab. Do not add administrative group membership merely to solve a file access problem. Do not enter real passwords into commands, scripts or chat.
Practice
Write the VM-only sequence for a non-admin account, including preflight, group creation, membership verification and snapshot rollback. Explain usermod -aG versus -G, and why account removal is not a complete file cleanup.
Related references
Study: useradd, usermod, userdel, groupadd, passwd, chage. These are reference names, not deployed links.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Managing users and groups — Knowledge Check
Apply the lesson concepts to the controlled account fixture.
Which option requests creation of a home with useradd?
Which form appends supplementary groups?
Does userdel without -r guarantee all owned files disappear?
What is the safe reset strategy for this lab?