Skip to main content
RunBook Academy

LinuxV · sudo and Privileged AccessPrivileged access

Root vs sudo — the production privilege model

Foundation⏱ ~8 minbashsudojournalctl

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

Not yet marked complete on this device.

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:

Concernsu -sudo
Per-command auditThe 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 exposureRoot password is shared with everyone in wheel.Each user authenticates with their own password; the root password is not shared.
Time-limited escalationPermanent session.By default, escalation lasts 5 minutes (configurable); re-authentication required after.
Per-host granularityGlobal.Each host’s /etc/sudoers is independent.
Read-only / Safesudo -l
$ sudo -l
Matching 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) ALL

Illustrative output

The sudo authentication flow

Common sudo invocations

Configuration changecommon 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
root

Illustrative output

Audit trail

Read-only / Safesudo audit
$ journalctl _COMM=sudo -n 20 --no-pager
Aug  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 ssh

Illustrative 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.

Configuration changeNOPASSWD
$ sudo -n systemctl status ssh
Active: active (running)

Illustrative output

Production discipline

PracticeWhy
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 filesKeeps each service’s policy in its own file, easy to audit and version-control.
Always run visudo to edit sudoersLocks the file during edit and validates syntax. A broken sudoers file can lock all admins out of root.
Forward the journal to your SIEMThe 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

  1. Q1. What is the primary production benefit of sudo over direct root login?

  2. Q2. A NOPASSWD rule scoped to a single command for a service account is a defensible configuration.

  3. Q3. Which of the following are correct sudo production disciplines? Select all that apply.

Passing score: 75%. Answers are checked in this browser.