auditd: who did what
How the Linux audit framework records file changes and privileged commands, a starter rule set to copy, how to read the results with ausearch and aureport, and what to watch for with log size, noise and locked rules.
Contents
Why auditd exists
Most logs on a Linux machine are written by the programs themselves. sshd says who logged in, sudo says what it was asked to run, nginx says what it served. Each program decides what to write, and a program that is compromised, misconfigured or simply quiet writes nothing useful.
The audit framework works one level down. The kernel watches system calls as they return and, when one matches a rule, writes a record about it: which process, which file, which user, whether it succeeded. The program never gets a say. The kernel side arrived in the Linux 2.6 series in 2004, built at Red Hat so that Linux could be certified against the Common Criteria’s Controlled Access Protection Profile, which required exactly this kind of record. auditd is the userspace daemon that receives those records and writes them to /var/log/audit/audit.log.
That makes it the tool for the questions that come up after something has gone wrong. Who edited /etc/sudoers on Tuesday? Which commands ran as root last night, and which person was behind them? A web log cannot answer either.
It is worth being clear about what auditd is not. It does not block anything: a rule records an action, it never refuses one. It is not an intrusion detection system, and it records only what the rules ask for, which by default on most distributions is almost nothing. It is also not a replacement for journald. The journal collects what services print; audit collects what the kernel saw them do. Without auditd running, the kernel still emits audit records and the journal may pick some of them up, but there is no dedicated log, no rotation or disk-full policy for it, and nothing for ausearch to read.
How it actually works
Three pieces do the work. The kernel matches events against a list of rules. auditd writes matching records to disk. ausearch and aureport read the disk back.
Rules come in two kinds. A file watch says “record anything that writes to this path”. A syscall rule says “record every call to this system call that matches these fields”. Both carry a key, a short label of your choosing (-k sudoers), and the key is what you search on later.
The field that makes audit worth having is auid, the audit or login user ID. When someone logs in, PAM’s pam_loginuid module writes their UID into /proc/self/loginuid. Every process they start inherits it, and it does not change when the identity does: su, sudo and setuid programs change the uid and euid, but the auid stays put. You can see it for yourself:
cat /proc/self/loginuid
sudo cat /proc/self/loginuid
Both print the same number. So when a command runs as root, the record says uid=root and also auid=alice, and the question “who was root at the time” has an answer. Processes started at boot by systemd never logged in, and their auid is unset, which the kernel stores as 4294967295 (the 32-bit form of -1) and the tools print as unset.
Installing it
On Fedora, RHEL and their relatives the package is audit, and it is usually installed and running already:
sudo dnf install audit
sudo systemctl enable --now auditd
On Debian and Ubuntu the package is auditd, and installing it starts the service:
sudo apt install auditd
Check that it is running and the kernel side is enabled:
sudo auditctl -s
enabled 1 means auditing is on. The same output shows lost and backlog, which matter later.
One Red Hat quirk: the auditd unit refuses systemctl stop and systemctl restart on purpose, and Red Hat’s documentation says to use service auditd restart instead, keeping systemctl for enable and status. You rarely need either. Rules load without a restart, and auditd rereads auditd.conf on SIGHUP.
Writing rules
Rules live in files ending in .rules under /etc/audit/rules.d/. Files with any other ending are ignored. augenrules joins them in natural sort order into /etc/audit/audit.rules, moves the control lines (-D, -b, -f, -e) to their proper places, and with --load sends the result to the kernel:
sudo augenrules --load
sudo auditctl -l
auditctl -l lists what the kernel actually has. Rules can also be added straight from the command line with auditctl, which is handy for testing, but those vanish at reboot. The files are the configuration.
Leave the file the package ships (usually audit.rules in the same directory) alone. It clears old rules and sets the buffer size and failure mode, and your own files go next to it.
File watches
-w /etc/sudoers -p wa -k sudoers
-w names the path. -p lists the access types to record: r read, w write, x execute, a attribute change (owner, mode, timestamps). wa is the usual choice for configuration: changes get logged, reads do not. On a directory the watch is recursive, so -w /etc/sudoers.d/ -p wa -k sudoers catches any file dropped into it.
The auditctl man page now calls the -w form deprecated, kept for backwards compatibility, and gives the syscall form as the replacement: -a always,exit -F arch=b64 -F path=/etc/sudoers -F perm=wa -k sudoers for a file, and -F dir= for a directory. Both forms still load on current releases. The starter set below uses -w because it is easier to read; convert the lines if you are writing rules for many paths.
Syscall rules
This one records every program run as root by a person who logged in:
-a always,exit -F arch=b64 -S execve -F euid=0 -F auid>=1000 -F auid!=unset -k root-cmds
-a always,exit -F arch=b32 -S execve -F euid=0 -F auid>=1000 -F auid!=unset -k root-cmds
Read it left to right. -a always,exit adds the rule to the exit list and always records a match. -F arch=b64 says which system call table to use, and it must come before -S. -S execve is the call that starts a program. -F euid=0 keeps only calls running with root’s effective UID. -F auid>=1000 keeps only real accounts, since 1000 is the default UID_MIN on Debian, Ubuntu, Fedora and RHEL. -F auid!=unset drops daemons that never logged in; unset, -1 and 4294967295 all mean the same thing here.
The rule appears twice because a 64-bit x86 kernel can also run 32-bit programs, and their system calls go through a separate table with different numbers. A rule for b64 alone never sees them, and anyone who knows that can run a 32-bit binary to stay out of the log. Write both.
A starter rule set
Two files. The first holds the rules:
## /etc/audit/rules.d/50-who-did-what.rules
# Accounts and groups
-w /etc/passwd -p wa -k identity
-w /etc/group -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/gshadow -p wa -k identity
# Who may use sudo
-w /etc/sudoers -p wa -k sudoers
-w /etc/sudoers.d/ -p wa -k sudoers
# SSH server settings
-w /etc/ssh/sshd_config -p wa -k sshd
-w /etc/ssh/sshd_config.d/ -p wa -k sshd
# The audit configuration itself
-w /etc/audit/ -p wa -k audit-config
# Every program run as root by a logged-in user
-a always,exit -F arch=b64 -S execve -F euid=0 -F auid>=1000 -F auid!=unset -k root-cmds
-a always,exit -F arch=b32 -S execve -F euid=0 -F auid>=1000 -F auid!=unset -k root-cmds
The second, added only after the first has run for a while without trouble, locks the rules:
## /etc/audit/rules.d/99-finalize.rules
-e 2
Load them with sudo augenrules --load.
Locking the rules
-e sets the audit state: 0 disables auditing, 1 enables it, and 2 enables it and locks the configuration. Once the kernel is in mode 2, no rule can be added, removed or changed and auditing cannot be turned off, by anyone, root included, until the machine reboots. auditctl -s then shows enabled 2.
That is the point. An intruder who gets root can otherwise run auditctl -D and erase the rules before doing anything interesting. In mode 2 the attempt fails, and the reboot needed to get around it is noticeable in itself.
The cost is the same for you. Every rule change needs a reboot, which is why the lock goes in last. augenrules always moves the -e line to the end of the combined file, so the name 99-finalize.rules is a convention for people reading the directory, not a requirement.
Reading the results
ausearch finds events. Search by key, and always add -i to turn numbers into names:
sudo ausearch -k sudoers -i
sudo ausearch -k root-cmds -i -ts today
sudo ausearch -ua alice -i -ts yesterday -te today
-ts and -te take a start and end time, either a date and time or a keyword: now, recent (ten minutes ago), today, yesterday, this-week, boot. -ua matches a user in the uid, euid or auid field. Other useful filters are -f for a file name, -x for an executable, -m for a record type such as EXECVE, and --success no for calls that failed.
One event is several records sharing a timestamp and serial number. For the root-cmds rule, trimmed down, it looks like this:
----
type=PROCTITLE msg=audit(11/04/2026 14:02:17.351:2214) : proctitle=systemctl restart nginx
type=CWD msg=audit(11/04/2026 14:02:17.351:2214) : cwd=/home/alice
type=EXECVE msg=audit(11/04/2026 14:02:17.351:2214) : argc=3 a0=systemctl a1=restart a2=nginx
type=SYSCALL msg=audit(11/04/2026 14:02:17.351:2214) : arch=x86_64 syscall=execve success=yes exit=0 ... auid=alice uid=root gid=root euid=root ... tty=pts0 ses=3 comm=systemctl exe=/usr/bin/systemctl key=root-cmds
EXECVE holds the full command line, CWD where it ran, and SYSCALL the identities. auid=alice with uid=root is the answer to “who did it”. ses is the login session number, so ausearch --session 3 -i pulls up everything else alice did in that session.
aureport turns the same log into summaries:
sudo aureport --summary
sudo aureport -k --summary
sudo aureport -x --summary -i
sudo aureport -au --failed -i -ts this-week
The first gives totals for the whole log. -k --summary counts events per key, which is the fastest way to spot a rule that is firing far more than it should. -x --summary ranks executables, and -au --failed lists failed authentication attempts.
Log size and rotation
auditd rotates its own log. Do not point logrotate at /var/log/audit/. The settings are in /etc/audit/auditd.conf:
max_log_file = 50
num_logs = 10
max_log_file_action = ROTATE
space_left = 500
space_left_action = SYSLOG
admin_space_left = 100
admin_space_left_action = SUSPEND
disk_full_action = SUSPEND
max_log_file is in MiB, so this keeps ten files of 50 MiB each. num_logs below 2 turns rotation off. space_left and admin_space_left are free-space thresholds in MiB on the log’s filesystem (recent versions also accept a percentage such as 25%), and the _action lines say what happens when they are crossed. SUSPEND stops writing records but keeps the daemon running; SINGLE drops the machine to single-user mode and HALT shuts it down, which some compliance regimes require and most servers should not do.
Apply changes with:
sudo pkill -HUP auditd
Records on the machine itself are only as trustworthy as the machine. An intruder with root can stop auditd or delete the files, even when the rules are locked. For anything that matters, ship the records elsewhere as they are written, with the audisp-remote plugin (package audispd-plugins on both Fedora and Debian) or through syslog to a central collector.
Noise and performance
Every syscall rule is checked on every matching system call, on every CPU, all the time. A few rules cost nothing you would notice. A rule on a busy call with no filters can generate thousands of records a second and slow the machine.
Three habits keep it in check. Always give syscall rules an -F arch=, because without one the kernel has to check the rule against every system call. Filter on auid so that daemons doing their normal work are excluded. Watch the key summary from aureport -k --summary after the first day, and cut or narrow any rule that dominates it.
Reads are the usual trap. -w /etc/shadow -p r records every login, every sudo and every cron job that checks a password. Record writes unless reads are what you are investigating.
When the kernel produces records faster than auditd takes them, they queue in a backlog, and when the backlog is full they are dropped. auditctl -s shows the count as lost. If it climbs, raise the buffer with a -b line (the shipped rules usually set -b 8192) or, better, cut the noise.
Troubleshooting
auditctl -l says No rules. The file probably does not end in .rules, or augenrules --load was never run. sudo augenrules --check reports whether the combined file is out of date.
augenrules --load fails with an error about the audit system being in immutable mode. The kernel is in mode 2, and auditctl -s will show enabled 2. Edit the files and reboot.
A rule loads but the expected events never appear. Check the filters before the rule. Commands run from cron or a systemd unit have an unset auid, so -F auid!=unset excludes them by design. A user whose UID is below 1000 is excluded by auid>=1000. A command that never ran as root does not match euid=0.
auditctl rejects the b32 line. Some 64-bit kernels, often on ARM, are built without 32-bit compatibility, so there are no 32-bit calls to catch and the line can go.
auditd will not start inside a container. The kernel accepts audit control only from the host’s initial namespaces. Run auditd on the host, where it sees the container’s processes anyway.
ausearch prints <no matches> for a key you know has fired. Check the spelling of the key, and check the time window: without -ts, ausearch reads every log file it has, but rotated files beyond num_logs are gone.
Where it fits
The earlier posts in this series are about keeping people out and limiting what a service can do: the firewall, SSH hardening, fail2ban and systemd sandboxing. auditd stops none of it. What it does is leave a record, written by the kernel rather than by the program being watched, of who changed the files that grant power and what they ran once they had it. The starter set above is a dozen lines. Load it, leave it unlocked for a week while you read aureport -k --summary, then add the -e 2 file and reboot.
Sources
- Linux Audit project. auditd(8), auditctl(8), audit.rules(7), augenrules(8), ausearch(8), aureport(8) and auditd.conf(5) manual pages.
- Linux-PAM. pam_loginuid(8) manual page.
- Red Hat. “Auditing the system.” Security hardening, Red Hat Enterprise Linux 9 documentation.
- Debian.
auditdandaudispd-pluginspackage descriptions, packages.debian.org.