Users and groups: useradd, usermod, userdel, passwd, id, /etc/passwd, /etc/shadow, sudo, wheel

Linux Essentials Preparation · lesson 19 of 23 · 25 min

Linux User Model

Linux is a multi-user OS. Every process and file is owned by a user. The root user (UID 0) has unrestricted access to everything. Regular users have UIDs ≥ 1000 (on most modern distros). System accounts (UIDs 1–999) run services like www-data, sshd, and nobody.

User Management Commands

Group Management Commands

sudo and Privilege Escalation

sudo (superuser do) allows authorized users to run commands as root without logging in as root. This is the preferred method — it logs all commands and limits exposure. The /etc/sudoers file controls who can use sudo (edit with visudo to prevent syntax errors).

On Ubuntu/Debian, adding a user to the sudo group grants full sudo access. On RHEL/CentOS, the group is wheel.

Flashcard Drill

root user UID 0 — unrestricted access to everything on the system. /etc/passwd User account database — username, UID, GID, home directory, shell. /etc/shadow Hashed passwords and password policy — readable only by root. useradd -m Creates a new user with a home directory. usermod -aG Adds a user to a supplementary group without removing existing groups. sudo Runs a command with root privileges — logs all usage. visudo Safe editor for /etc/sudoers — validates syntax before saving. id Shows UID, GID, and all group memberships for a user. su – Switches to another user with a full login shell. wheel group RHEL/CentOS sudo group — members can use sudo.

Worked Scenario: User Administration

Scenario

A new developer named “bob” needs to be added to the system. He needs a home directory, bash as his shell, and must be able to use sudo. Write the commands.

Step 1 — Create the user: useradd -m -s /bin/bash bob

Step 2 — Set a password: passwd bob

Step 3 — Add to sudo group (Ubuntu/Debian): usermod -aG sudo bob

Step 4 — Verify: id bob — should show uid, gid, and groups including sudo.

On RHEL/CentOS, replace sudo with wheel in step 3: usermod -aG wheel bob

Knowledge Check — 12 Questions

Users & Groups (Linux Essentials)

Which file contains hashed passwords and is readable only by root?

  • /etc/passwd
  • /etc/shadow
  • /etc/group
  • /etc/sudoers

Answer: /etc/shadow
/etc/shadow stores hashed passwords and password aging policy — restricted to root.

Which command adds user alice to the sudo group?

  • useradd alice sudo
  • usermod -aG sudo alice
  • gpasswd alice sudo
  • addgroup alice sudo

Answer: usermod -aG sudo alice
usermod -aG appends alice to the sudo group without removing her from other groups.

The UID of the root user is _____.

Answer: 0
Root always has UID 0 — the kernel grants unrestricted access to UID 0.

Which command shows the UID, GID, and group memberships of the current user?

  • whoami
  • id
  • groups
  • passwd

Answer: id
id shows UID, primary GID, and all supplementary groups for the current or specified user.

Which tool should you use to edit /etc/sudoers?

  • nano
  • vim
  • visudo
  • cat

Answer: visudo
visudo validates sudoers syntax before saving — a syntax error in sudoers can lock you out of sudo.

On RHEL/CentOS, the sudo group is called “sudo”.

  • True
  • False

Answer: False
On RHEL/CentOS, the sudo group is called “wheel”. On Ubuntu/Debian it is “sudo”.

Which command creates a new user with a home directory?

  • adduser
  • useradd -m
  • newuser
  • createuser

Answer: useradd -m
useradd -m creates the user and their home directory. Without -m, no home directory is created.

Which command deletes user alice AND removes her home directory?

  • userdel alice
  • userdel -r alice
  • usermod -d alice
  • rmuser alice

Answer: userdel -r alice
userdel -r removes the user account and their home directory and mail spool.

To run a command as root without logging in as root, use the _____ command.

Answer: sudo
sudo (superuser do) runs a command with root privileges and logs the action.

System accounts (for services like sshd, www-data) typically have UIDs in which range?

  • 0
  • 1–999
  • 1000–9999
  • 10000+

Answer: 1–999
System/service accounts use UIDs 1–999. Regular users start at UID 1000 on most modern distros.

Which file contains group definitions and their members?

  • /etc/passwd
  • /etc/shadow
  • /etc/group
  • /etc/sudoers

Answer: /etc/group
/etc/group contains group names, GIDs, and member lists.

What does the -aG flag in usermod -aG sudo alice do?

  • Removes alice from all groups
  • Appends alice to the sudo group without removing existing groups
  • Creates a new group called sudo
  • Grants alice root access permanently

Answer: Appends alice to the sudo group without removing existing groups
-a = append, -G = supplementary groups. Without -a, usermod -G would replace all existing group memberships.


Previous lesson: Boot process: BIOS/UEFI, GRUB, kernel, initramfs, systemd targets
Back to Linux Essentials Preparation
Next lesson: File permissions and security: chmod, chown, SUID/SGID/sticky bit, SSH hardening, ufw, Fail2ban