Scenario
You are onboarding two new developers: devstudent and devstudent2.
The team needs a shared group called devteam and a shared workspace at
/opt/devwork owned by that group. You will create one account using a minimal
baseline workflow, create the second using advanced useradd flags, verify identity
and group state using system files and CLI tooling, then clean up all changes.
This is the user onboarding workflow you run when you want repeatable outcomes and clear verification, not “I think the account exists.”
Objective
- Create a team group and two user accounts (basic and advanced methods).
- Set passwords and enforce correct primary group assignment.
- Create a shared directory and assign correct group ownership recursively.
-
Verify user records and group membership using
/etc/passwd,id, and/etc/group. - Remove accounts and group cleanly, including home directory cleanup.
Concepts
- Group-first onboarding ensures consistent file ownership in shared workspaces and reduces permission drift.
- Minimal user creation relies on system defaults. Explicit user creation is repeatable and auditable.
- Primary group affects default group ownership on new files. Supplementary groups affect access without changing defaults.
- Verification is evidence: confirm account records and membership via system databases and CLI outputs.
- Cleanup should be complete and ordered: remove users (and homes) before removing the group they depended on.
Walkthrough
sudo groupadd devteam
The group is the shared access boundary. Create it first so both users can be anchored to the same team identity.
getent group devteam
sudo useradd devstudent
This creates the user using system defaults. Home directory creation depends on distro defaults and configuration.
sudo passwd devstudent
Password assignment completes the onboarding baseline and allows interactive login, subject to policy and account state.
sudo usermod -g devteam devstudent
Primary group affects default group ownership for new files. This aligns the user with the team by default.
sudo useradd -g devteam -s /bin/bash -c "Dev employee" -m -d /home/devstudent2 devstudent2
This form is repeatable: define primary group, shell, comment, home directory path, and ensure the home directory exists immediately.
sudo passwd devstudent2
With the account created and home provisioned, password is the final access step before verification.
sudo mkdir -p /opt/devwork
sudo chgrp -R devteam /opt/devwork
This creates the directory and ensures all content under it is owned by the shared group. This is the minimum needed for controlled team collaboration.
ls -ld /opt/devwork
grep devstudent /etc/passwd
grep devstudent2 /etc/passwd
This verifies the local account records and shows UID, primary GID, home, and shell fields.
id devstudent
id devstudent2
getent group devteam
Confirm the primary group is the team group, and confirm the group entry reflects expected membership.
sudo userdel -r devstudent
sudo userdel -r devstudent2
sudo rm -rf /opt/devwork
sudo groupdel devteam
Remove users first, then remove the shared directory, then remove the group last to ensure nothing depends on it.
Breakpoints
Minimal user creation may not create a home directory depending on system defaults.
Confirm the record in /etc/passwd and decide whether to re-create the user using
useradd with -m.
If a user’s primary group is the team group, it may not appear in the member list of the
group entry. Validate primary GID via id and the group record via
getent group.
A group cannot be removed if it is still referenced as a primary group for an existing user.
Remove users first, then retry groupdel.
Cleanup checklist
-
Confirm both users are removed from
/etc/passwdand no home directories remain. -
Confirm the shared workspace at
/opt/devworkis removed. -
Confirm the group is removed from
/etc/group.
getent passwd devstudent
getent passwd devstudent2
getent group devteam
ls -ld /opt/devwork
Reference
-
groupadd: Creates a new group. -
useradd: Creates a user account.-g: Set primary group.-s: Set login shell.-c: Set comment field.-m: Create home directory.-d: Set home directory path.
-
passwd: Sets or changes a user password. -
usermod: Modifies an existing user account.-g: Change primary group.
-
mkdir: Creates directories.-p: Create parent directories as needed.
-
chgrp: Changes group ownership.-R: Apply recursively.
-
id: Displays UID, primary GID, and group memberships. -
getent: Queries system databases. -
grep: Searches text patterns in files. -
userdel: Deletes a user account.-r: Remove home directory and mail spool.
-
groupdel: Deletes a group. -
/etc/passwd: Local user account database. -
/etc/group: Local group membership database. -
/opt/devwork: Shared workspace path used in this lab.