We are still cooking the magic in the way!
Users, Groups & sudo
Users, Groups & sudo
Every process, file, and network connection on a Linux system runs under an identity. That identity determines what it can read, write, and execute. Understanding Linux's user and group model is not optional background knowledge for a DevOps engineer — it is the foundation of least-privilege security, the reason automated CI runners don't run as root, and the first thing an auditor checks after a breach. This lesson teaches the model the way production engineers think about it: mechanically precise and security-first.
The /etc/passwd File
Despite its name, /etc/passwd no longer stores passwords (those moved to the shadow file decades ago). It stores the seven fields that define every user account on the system. Read it directly — it is world-readable and no tool hides its structure.
The UID ranges you will encounter on every Linux distribution:
- UID 0 —
root. One account, unlimited power. The kernel bypasses permission checks for UID 0. - UID 1–999 — System accounts. Created by package managers for daemons (
www-data,postgres,redis). They have/usr/sbin/nologinas their shell — no one can log in as them interactively. - UID 1000+ — Human users. First human account is conventionally 1000 on Debian/Ubuntu, 1000 on RHEL/Amazon Linux.
www-data can only read files world-readable or owned by www-data. A compromised www-data process cannot touch /home/ubuntu or read other services' secrets. This is the principle of least privilege applied to process identity.
Groups — Sharing Access Without Sharing Identity
A group is a named set of users that can be granted permissions collectively. Every file has an owner (a UID) and an owning group (a GID). The permission bits are split across three classes: owner, group, and other.
Group membership is stored in /etc/group:
The most operationally important groups in a typical DevOps environment:
- sudo (Debian/Ubuntu) / wheel (RHEL/Amazon Linux) — grants
sudoaccess - docker — allows running Docker commands without
sudo(be careful: this is effectively root on the host) - adm — allows reading system log files in
/var/log - www-data — used by nginx/Apache; deploy scripts often add the deploy user here to write to web roots
Creating and Managing Users
On production servers you will create two kinds of accounts: human operator accounts and service accounts. The commands differ slightly between them.
The Root Account and the sudo Model
UID 0 (root) is the superuser. The Linux kernel grants it unconditional access to every file, every process, every device. Direct root login is almost universally disabled on production servers — the root password is unknown, and SSH PermitRootLogin is set to no. Instead, access is mediated through sudo.
su vs sudo:
su - root— opens a root shell. Requires knowing the root password. Leaves no per-command audit trail. Strongly discouraged in modern production.sudo command— elevates a single command. Requires your own password. Every invocation is logged to/var/log/auth.log(or journald) with the calling user, the command, and the working directory. This is the model all major cloud providers use.
sudo group. A CI runner, a deploy user, or an application process should accomplish its work through file permissions and group membership, not elevated privileges. If your deploy script needs to restart nginx, give it a specific sudoers entry for that one command — not unrestricted sudo. An attacker who compromises that process should find a narrow blast radius.
Configuring sudo with /etc/sudoers
The sudo policy lives in /etc/sudoers and the directory /etc/sudoers.d/. Always edit with visudo — it validates syntax before saving, preventing a malformed file from locking you out.
sudo Audit Trail
Every sudo invocation is logged. On systemd distributions the authoritative source is the journal; the traditional file is /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL). At big-tech scale these logs are forwarded to a SIEM (Splunk, Elastic, Chronicle) and alerted on for anomalies — unexpected root commands during off-hours, commands from a service account, or failed sudo attempts (password spraying).
NOPASSWD sudo rights scoped to exactly the commands it needs. Never NOPASSWD: ALL — that is equivalent to handing out root access unconditionally. Combine with SSH key-only authentication and no interactive shell (/usr/sbin/nologin) for the tightest possible automation account.
Switching Users and Running as Another Identity
Understanding the difference between su, sudo -i, and sudo -u matters when debugging permission issues on production:
sudo -i— opens a root login shell (loads root's environment). Use sparingly; prefer per-command sudo.sudo -u deploy command— run a single command as thedeployuser. Essential for testing "what can this service account actually do?"sudo -s— opens a root shell preserving your current environment. Useful for diagnosing environment-variable issues.su - deploy— switch to thedeployuser with a full login. Requires knowing deploy's password or having root. Used less often now thatsudo -uis available.
In Lesson 6 you will see how these identities and the permission bits on files interlock — the rwxr-xr-x strings you have seen in ls -l output will finally make complete mechanical sense once you understand the user model you have built here.