auditd is the Linux kernel’s audit subsystem in userland — the canonical way to know who ran which syscall against which file when. Most distros enable it but ship no operational rules, so it sits at idle producing nothing useful. This article gives a starter set of rules tuned for production: enough coverage to satisfy a Center for Internet Security review, not so verbose that the log eats the disk.
How to verify
Confirm the daemon is running, the rules are loaded, and the log is rotating:
sudo systemctl status auditd
sudo auditctl -l
sudo auditctl -s
sudo ausearch -k privileged --start today
sudo aureport --summary
ls -lh /var/log/audit/
auditctl -l lists every active rule. auditctl -s shows the daemon state, including the backlog (unwritten events queued in kernel buffers) — a non-zero backlog under load means the rules are too expensive or the log disk is too slow.
What’s happening
auditd reads rules from /etc/audit/rules.d/*.rules at boot and compiles them into kernel filters via the audit netlink interface. The kernel writes matching events to /var/log/audit/audit.log. Rules come in three flavours: file-watches (-w /etc/passwd -p wa -k passwd_changes), syscall rules (-a always,exit -F arch=b64 -S execve), and control rules (buffer sizes, failure mode). The -k key tags events for later filtering with ausearch -k.
The danger is over-collection. A rule that watches every read syscall in production buries the signal in noise and may push events faster than the kernel can drain them — auditd’s default failure=1 (printk warning) then escalates to failure=2 (panic) if you set it. The right strategy is to watch specific privileged actions, integrity-sensitive paths, and the syscalls associated with privilege escalation, not “everything”.
CIS and STIG benchmarks ship recommended rule sets. The audit-rules package on Debian/Ubuntu and audit on RHEL family include 30-stig.rules.disabled and similar — rename to enable.
The procedure
- Increase the kernel buffer for high-throughput hosts. Edit
/etc/audit/rules.d/00-control.rules:-b 16384(default is 8192) and-f 1(printk on failure, not panic). Reload withsudo augenrules --load. - Drop in the bundled hardening rules.
sudo cp /usr/share/doc/auditd/examples/rules/30-stig.rules /etc/audit/rules.d/(path varies by distro). Review before loading — some rules reference paths that may not exist on your host. - Watch privilege escalation.
-a always,exit -F arch=b64 -S execve -F uid!=0 -F euid=0 -k root_execcatches every binary executed where the real UID was non-root but the effective UID is root — typically sudo-mediated privilege escalation. - File integrity for the paths that matter.
-w /etc/passwd -p wa -k identity,-w /etc/shadow -p wa -k identity,-w /etc/sudoers -p wa -k identity,-w /etc/sudoers.d/ -p wa -k identity. Thewapermission set covers writes and attribute changes. - Capture loadable kernel modules.
-w /sbin/insmod -p x -k modules,-w /sbin/rmmod -p x -k modules,-w /sbin/modprobe -p x -k modules,-a always,exit -F arch=b64 -S init_module,delete_module -k modules. - Apply and verify.
sudo augenrules --loadthensudo auditctl -l | wc -lto confirm rules are in the kernel. Trigger an event (sudo touch /etc/passwd-test && sudo rm /etc/passwd-test) andsudo ausearch -k identity --start recentto confirm it logged. - Configure retention.
/etc/audit/auditd.confcontrols log rotation:max_log_file = 50(MB),num_logs = 10,max_log_file_action = ROTATE,space_left = 1000,space_left_action = SYSLOG,admin_space_left_action = SUSPEND. TheSUSPENDaction stops auditing rather than overwriting — appropriate for a compliance posture. - Forward events to a SIEM.
audisp-syslog(oraudisp-remote) plugs into the audit dispatcher and ships every event to a remote syslog. Configure under/etc/audit/plugins.d/syslog.conf.
Common pitfalls
- The
-a always,exitclause is required for syscall rules to produce events. Bare-S execvewithout the action does nothing. - A rule on
arch=b64only matches 64-bit syscalls. On a host that runs 32-bit binaries (some legacy CI), you need botharch=b32andarch=b64versions. -wfile watches use inotify under the hood — they fire on the path, not the inode. A file replaced atomically (write-then-rename) is seen as a new watch target and the old watch loses scope.ausearch -kplus a key on the parent directory is more reliable for some patterns.- Keys are advisory, not enforced. Reusing a key across many rules makes
ausearchmore useful but loses the per-rule attribution. Use distinct keys for distinct intents. - The
auditpackage on RHEL family installsauditdas a non-systemd-managed daemon for historical reasons —systemctl restart auditdworks butsystemctl reload auditddoes not. Useservice auditd restartor apply rules withaugenrules --load.
In the engagements we run, auditd rules are part of the standard build and the events stream to a SIEM that the security team owns. The retention, forwarding, and rotation pieces live in Managed Operations — auditing without retention is theatre.