Auditing with auditd
Record who touched sensitive files and what ran, with the kernel audit system: write rules, keep them in rules.d, search with ausearch and aureport.
Kernel space, user space and system callsPAM and the login pathjournald and journalctlSELinux
Auditing with auditd
The player loads from youtube-nocookie.com when you press play. Nothing reaches YouTube before that.
Not started
What you'll learn
- The audit system records security events from inside the kernel, at the system call. A process cannot avoid it the way it could avoid writing an application log.
- Rules either watch a path for read, write, execute or attribute changes, or match system calls. Current auditctl documentation calls the old `-w` watch form deprecated and prefers `-a always,exit -F path=... -F perm=...`.
- Tag every rule with `-k` so you can find its events later. Keep rules in `/etc/audit/rules.d/*.rules`, which `augenrules` merges into `/etc/audit/audit.rules`.
- Each event carries the `auid`, the login user ID set at login, which stays the same through `sudo` and `su`. That is how an audit trail says which person acted.
- `ausearch -k <key> -i` finds and decodes events. `aureport` summarises them, for example `aureport -au` for authentication and `aureport --failed` for failures.
- Every syscall rule is checked on every matching syscall, so too many rules cost performance. Audit what you will actually review.
Logs that the actor cannot edit
After an incident, someone always asks: who changed this file, and when? The application log will not say, because the change did not go through the application. The shell history is gone, or was never written. The journal shows that sudo was used, but not what was done with it.
The Linux audit system answers from a better position. The kernel itself emits a record when a system call matches a rule, before the calling program has any say. A daemon, auditd, writes those records to /var/log/audit/audit.log. Think of the difference between a shop’s own sales ledger and the CCTV over the till. The ledger is only as honest as the person filling it in.
The system-call boundary is the one from kernel space, user space and system calls, and it is why the audit trail is hard to dodge.
Two kinds of rule
File rules record access to a path. The classic form is a watch:
-w /etc/shadow -p wa -k identity
-p takes r, w, x and a (attribute change). -k attaches a key, a label up to 31 bytes, that you search on later. The current auditctl man page calls the -w form “deprecated due to poor system performance” and recommends the syscall-style equivalent, which is the same rule with explicit fields:
-a always,exit -F arch=b64 -F path=/etc/shadow -F perm=wa -k identity
-a always,exit -F arch=b64 -F dir=/etc/sudoers.d/ -F perm=wa -k sudoers
Syscall rules match system calls by name, with filters:
-a always,exit -F arch=b64 -S execve -F euid=0 -F auid>=1000 -F auid!=unset -k root-exec
That one records every program a logged-in human runs as root. The man page insists on -F arch=: without it, a rule applies to both 32-bit and 64-bit syscalls, which have different numbers. Rule order matters too, since the first match wins.
The auid
Every event carries several user IDs. The one that matters most is the auid, the login UID. It is set once when a person logs in, through pam_loginuid in the PAM stack, and does not change when they run sudo or su. So a record of root editing /etc/sudoers still names the person who logged in. The ausearch man page notes that entry points must use pam_loginuid for auid searches to be accurate.
Keeping rules
Rules added with auditctl live in the kernel until reboot. Persistent rules go in files under /etc/audit/rules.d/, ending in .rules. The augenrules man page says it merges them in natural sort order into /etc/audit/audit.rules, always moving -D (delete all) to the top and the last -e to the bottom.
sudo augenrules --load
sudo auditctl -l # what the kernel has now
-e 2 as the last line locks the configuration. The man page says it “can only be changed by rebooting the machine”. An attacker with root cannot silently disable auditing, and neither can you, so add it only once the rules are settled.
Finding events
ausearch finds raw events, and aureport summarises:
sudo ausearch -k identity -i -ts today
sudo ausearch -m USER_LOGIN --success no -ts recent
sudo aureport --summary
sudo aureport -au --failed # failed authentications
sudo aureport -x --summary # which executables appear most
-i turns numbers into names, such as UIDs into user names, using the local machine’s accounts. The man page warns this can mislead if the logs came from another machine. -ts recent means the last ten minutes. The SELinux denials from the SELinux lesson are audit records too, type AVC, which is why they are found with the same tool.
What to audit
A useful starting set is small: identity files (/etc/passwd, /etc/shadow, /etc/group), sudo configuration, SSH server configuration, root executions by logged-in users, and module loading. The man page is blunt that “too many syscall rules will hurt performance”. Every rule is a cost paid on each matching syscall, and an audit log nobody reads protects nobody. If you need to retain the records, forward them off the machine, because locked rules do not stop an attacker with root from deleting the local log files.
The audit system needs Linux, so nothing here was run. Rules and commands are written from the auditctl, augenrules, ausearch and aureport man pages on man7.org, checked 2026-11-28.
About the video
The embed is all of “Mastering AuditD: Efficient Logging and Rule Management” from the Red Hat Enterprise Linux channel, June 2025, about 11 minutes. Its chapters cover what audit logging is, implementing new audit rules, the metadata in records, log rotation, the log files themselves and sample rule configuration. Going by its chapters it does not demonstrate aureport, which this lesson covers. For a longer hands-on run that watches the identity and sudo files, CloudSecLab’s 2026 video is in deeper. I judged the embed from its chapters and description, and English from its English caption track.
Where this fits
Auditing tells you what happened. The cheapest way to keep bad things from happening is keeping software current: patching and automatic updates.
Check yourself
Why does an audit record of a change to `/etc/sudoers` still show who did it, even though the change was made by root through sudo?
The record includes the auid, the login UID assigned when that person logged in through PAM. It does not change when they use sudo, so it names the person, not just root.
What rule records every write or attribute change to `/etc/passwd`, tagged so it is easy to search?
`-a always,exit -F arch=b64 -F path=/etc/passwd -F perm=wa -k identity`, placed in a file under `/etc/audit/rules.d/` and loaded with `augenrules --load`.
What does `-e 2` at the end of the rules do, and what is the catch?
It makes the audit configuration immutable until the next reboot, so an attacker with root cannot quietly turn auditing off. The catch is that you cannot change rules either without rebooting.
You add 40 broad syscall rules and the server's latency rises. Why?
Syscall rules are evaluated on syscalls as they happen, so each extra rule adds work to every matching call. Narrow them with filters, combine rules that share fields, and audit only what you will review.
Go deeper
Notes
Notes are saved to your account.
Everything else on this page works without one — progress and bookmarks keep themselves in this browser and come with you when you sign in. Notes are the one thing worth not trusting to a browser you might clear.
Your notes could not be loaded.