LinuxV · sudo and Privileged AccessPrivileged access
Root vs sudo — the production privilege model
What you'll learn
- Explain why direct root login is forbidden in production
- Use sudo to run commands with elevated privileges
- Configure NOPASSWD safely and recognise its dangers
- Audit sudo invocations from the journal
Prerequisites
Verified against Ubuntu 24.04 LTS · Debian 12 (Bookworm) · RHEL 9.x · Rocky Linux 9.x · AlmaLinux 9.x · Linux kernel 6.1 LTS / 6.6 LTS · systemd 255+ · OpenSSH 8.7p1 (RHEL 9) / 9.6p1 (Ubuntu 24.04) · nftables 1.0.x · chrony 4.x · Pacemaker 2.1.x · Corosync 3.1.x · 2026-08-09
sudo is the canonical privilege-escalation tool on modern Linux.
Every production host ships with it; every policy document
references it; every compliance audit checks it. Understanding sudo
is not optional.
Why direct root login is forbidden
The historical alternative to sudo was su - (or just logging in
as root directly). Both produce the same outcome: a session with
UID 0. Both have the same problem: the audit trail is what
the root user decides to write down.
sudo’s discipline is different:
| Concern | su - | sudo |
|---|---|---|
| Per-command audit | The su invocation is logged; the resulting commands are not. | Every command is logged with timestamp, user, TTY, and command. |
| Per-user access | “Members of wheel get root” | Each user gets a specific list of allowed commands. |
| Password exposure | Root password is shared with everyone in wheel. | Each user authenticates with their own password; the root password is not shared. |
| Time-limited escalation | Permanent session. | By default, escalation lasts 5 minutes (configurable); re-authentication required after. |
| Per-host granularity | Global. | Each host’s /etc/sudoers is independent. |
$ sudo -lMatching Defaults entries for alice on host01:
env_reset, mail_badpass, secure_path=/usr/local/sbin\\:/usr/local/bin\\:/usr/sbin\\:/usr/bin\\:/sbin\\:/bin, use_pty
User alice may run the following commands on host01:
(ALL) ALLIllustrative output
The sudo authentication flow
Common sudo invocations
$ sudo systemctl status ssh; sudo -u www-data whoami; sudo -i● ssh.service - OpenBSD Secure Shell server
Loaded: loaded (/lib/systemd/system/ssh.service; enabled)
Active: active (running) since ...
www-data
rootIllustrative output
Audit trail
$ journalctl _COMM=sudo -n 20 --no-pagerAug 9 12:00:01 host sudo[12345]: alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/systemctl status ssh
Aug 9 12:00:42 host sudo[12346]: alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/systemctl restart sshIllustrative output
NOPASSWD and its risks
NOPASSWD removes the password prompt. Used carelessly, it turns
sudo into the very thing it was designed to replace: a permanent
elevation.
$ sudo -n systemctl status sshActive: active (running)Illustrative output
Production discipline
| Practice | Why |
|---|---|
Disable direct root login (PermitRootLogin no in sshd_config, passwd -l root) | Forces every privileged action through sudo, which is auditable. |
Disable su (remove the su PAM group, or remove wheel membership) | Forces every privileged action through sudo, not the unaudited su flow. |
Use /etc/sudoers.d/<service> drop-in files | Keeps each service’s policy in its own file, easy to audit and version-control. |
Always run visudo to edit sudoers | Locks the file during edit and validates syntax. A broken sudoers file can lock all admins out of root. |
| Forward the journal to your SIEM | The audit trail is the only post-incident record of what privileged actions occurred. |
Set timestamp_timeout to a short value (5-15 minutes) | Limits the window of unattended-terminal abuse. |
Knowledge check
Knowledge check · 3 questions
Q1. What is the primary production benefit of sudo over direct root login?
Q2. A NOPASSWD rule scoped to a single command for a service account is a defensible configuration.
Q3. Which of the following are correct sudo production disciplines? Select all that apply.
Passing score: 75%. Answers are checked in this browser.