Users, Groups & sudo
Linux was designed from day one to be a multi-user system. Every process runs as a user, every file has an owner, and the kernel enforces who can access what. Understanding this model is fundamental to understanding security in Linux.
Users and UIDs
Every user has a unique numeric ID called a UID (User ID). The kernel uses UIDs internally — it doesn't care about usernames. The mapping from name to UID lives in /etc/passwd.
/etc/shadow, which only root can read. The "x" means "look in shadow." This prevents regular users from seeing password hashes and running offline cracking attacks.
UID ranges by convention:
- 0 — root (superuser, can do anything)
- 1–999 — system accounts (daemons: www-data, mysql, nobody)
- 1000+ — regular human users
Groups and GIDs
Groups let you share access between multiple users without making files world-readable. Each user has a primary group (set in /etc/passwd) and can belong to multiple supplementary groups.
Common groups to know: sudo/wheel (admin), docker, video, audio, www-data.
The Root User
Best practice: never log in as root directly. Use sudo for specific privileged commands.
How sudo Works
sudo binary is SUID root — it always runs with root's UID. When you invoke it: (1) sudo checks /etc/sudoers to see if you're allowed, (2) authenticates you via PAM (your password), (3) forks a child process with root's UID, (4) runs your command.
The sudoers file syntax:
su vs sudo
| sudo | su | |
|---|---|---|
| Authenticates with | Your own password | Target user's password |
| Logs to | /var/log/auth.log (full audit) | Less detailed |
| Scope | One command at a time | Full session as target user |
| Best for | Specific privileged tasks | Switching to service accounts |