Skip to content
Lesson: sudo EventsSwitch
← Security Operations

Security investigations

sudo Events

Review who used sudo, what they ran and which attempts were refused.

sudo runs a command as another user, usually root, and records it. Those records tell you who used elevated rights on your system.

A successful command

text
Mar  3 10:02:11 web1 sudo:    alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/systemctl restart nginx

alice is who ran sudo. TTY is the terminal, PWD the directory, USER the target account and COMMAND the program with its arguments. Session open and close messages from PAM often appear nearby.

Find them with the journal, or in /var/log/auth.log (Debian, Ubuntu) or /var/log/secure (Fedora, RHEL):

bash
sudo journalctl _COMM=sudo --since today

Some distributions ship a different sudo implementation, such as sudo-rs on recent Ubuntu releases, whose messages and options may differ.

Refusals and mistakes

Messages from the original sudo include phrases like these:

text
alice : 1 incorrect password attempt ; TTY=pts/0 ; ...
bob : user NOT in sudoers ; TTY=pts/1 ; ...
alice : command not allowed ; TTY=pts/0 ; ...

A single typo is normal. Repeated refusals, or an account that should never need root trying to use it, are worth a question.

What the log cannot show

If someone runs sudo -i or sudo bash, sudo records that a root shell started, but ordinarily not the commands typed inside it. The same applies to programs that can start a shell, such as some editors. Grant specific commands where possible, and use sudoedit for editing files. For deeper recording, consider sudo's I/O logging or the audit system.

Review rights

bash
sudo -l
sudo -l -U bob

The first lists your own rights; the second lists another user's, and needs suitable privilege. Edit rules only with sudo visudo, or sudo visudo -f /etc/sudoers.d/name, which checks syntax before saving. A broken sudoers file can lock you out of root access.

Membership of an admin group, sudo on Debian and Ubuntu or wheel on Fedora and RHEL, often grants broad rights, so review those lists too.

Try it

On your own machine, run sudo id, then find the matching log line and name each field. Run sudo -l to read your rights. The accounts and access files lab covers related files.

Check your understanding

sudo Events

All 4 sections · no timer

Unlimited retries

Questions from every section are combined into one assessment. Answer them all correctly to complete the article.

Your completion saves in this browser. Sign in to sync it to your account.