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
Mar 3 10:02:11 web1 sudo: alice : TTY=pts/0 ; PWD=/home/alice ; USER=root ; COMMAND=/usr/bin/systemctl restart nginxalice 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):
sudo journalctl _COMM=sudo --since todaySome 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:
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
sudo -l
sudo -l -U bobThe 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.