Linux auditd Explained: Audit Who Did What on Your Server
A file changed on your server. A user account was modified. A config file was edited at 3 a.m. Who did it? Without auditing, you are guessing. Linux ships with a built-in answer: auditd, the Linux Auditing System. It records who ran what, which files were touched, and when — a security camera for your server. Here is how it works.
What auditd Does
auditd is a daemon that watches the kernel for events you define and writes them to a log, usually /var/log/audit/audit.log. Unlike normal system logs, which record what programs say happened, audit records are generated by the kernel itself — so they capture actions even when the program involved stays silent.
Typical events it can record:
- A user running sudo or switching accounts.
- A file being read, written or executed.
- A login, successful or failed.
- A system call like changing file permissions or loading a kernel module.
Installing and Starting auditd
On Debian/Ubuntu:
sudo apt install auditd audispd-plugins
sudo systemctl enable --now auditd
On RHEL/Fedora it is usually preinstalled. Check it is running:
sudo systemctl status auditd
Writing Your First Rules
auditd only records what you tell it to watch. Rules live in /etc/audit/rules.d/ and are loaded with augenrules. A few high-value starting rules:
# Watch the password and shadow files — any access is suspicious
-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
# Watch SSH config and keys
-w /etc/ssh/sshd_config -p wa -k sshd-config
-w /root/.ssh/ -p wa -k ssh-keys
# Log every use of sudo
-w /usr/bin/sudo -p x -k sudo-use
# Watch for kernel module loading (a classic rootkit move)
-w /sbin/insmod -p x -k modules
-w /sbin/modprobe -p x -k modules
# Watch changes to the audit rules themselves
-w /etc/audit/ -p wa -k audit-config
The -p wa means log writes and attribute changes; -p x means log executions; -k gives the rule a searchable tag.
Apply the rules:
sudo augenrules --load
Reading the Logs
Raw audit logs are dense. Use ausearch to filter them:
# Everything tagged "identity" (password file access)
sudo ausearch -k identity
# All sudo usage today
sudo ausearch -k sudo-use --start today
# Failed events only
sudo ausearch --success no
# What did user "anony" do?
sudo ausearch -ua anony --start today
For a human-readable summary, aureport is your friend:
sudo aureport --summary
sudo aureport --auth
sudo aureport --file
sudo aureport --failed
A Real-World Example
Imagine your web server config changed overnight. Instead of guessing:
sudo ausearch -k sshd-config --start yesterday
You get the exact time, the user, the process, and the command. That is the difference between an investigation and a shrug — and in incident response, that difference is everything.
Tips That Matter
- Protect the logs. Audit logs are evidence — send them to a remote syslog server so an attacker who compromises the box cannot erase their own trail.
- Start small. Auditing every file access on a busy server creates mountains of noise. Watch the sensitive files first, then expand.
- Rotate the logs. auditd can fill a disk; set max_log_file and num_logs in /etc/audit/auditd.conf.
- Never disable it on a production server to “save performance” — the cost of blindness is always higher.
auditd turns “something happened” into “this user ran this command at this exact second.” Set it up before you need it — because by the time you need it, it is too late to start recording.



Comments
Post a Comment