Auditd is the Linux kernel audit daemon. It logs system events to a persistent record that survives reboot and tampering. The rules you write determine what gets logged — too few rules and you miss incidents; too many and you drown in noise.
Audit rules fall into four categories: file watches, system call rules, exclude rules, and control rules. Each targets a different signal. This piece walks the syntax, shows working examples, and flags the gotchas.
The Audit Rule Model
An audit rule has this structure:
auditctl -a action,filter -S syscall_name -F field=value -k key_name
Action is always (log all) or never (exclude).
Filter is where in the kernel event pipeline the rule applies: task (fork/exec), exit (syscall return), user (user-space messages), or exclude (never audit).
Syscall is the system call name (e.g., open, execve, connect).
Field is a context matcher: uid, gid, comm (command name), name (filename), arch, success.
Key is a label for parsing logs later. Use meaningful names: file_write, auth_attempt, suspicious_exec.
The filter exit is most common—it logs the result of the syscall, including whether it succeeded or failed. This is where you catch both successful attacks and failed attempts.
File Watch Rules
File watches monitor specific files or directories. They're simpler than syscall rules and ideal for high-value targets.
auditctl -w /etc/passwd -p wa -k passwd_changes
auditctl -w /etc/sudoers -p wa -k sudoers_changes
auditctl -w /root/.ssh -p wa -k root_ssh_changes
-w specifies the watch path.
-p sets permissions: r (read), w (write), x (execute), a (attribute change).
This rule fires whenever anyone modifies /etc/passwd. The log entry includes the uid, command, and the old/new value (if available). Use this for configuration files, SSH keys, and cron jobs.
Gotcha: Watch rules don't log reads, only writes and attribute changes. If you need to detect who's reading /etc/shadow, you need a syscall rule, not a watch.
Syscall Rules: Common Patterns
Syscall rules are precise. They log calls that match your filter before (or after) they execute.
Monitor all file opens
auditctl -a exit,always -S open -S openat -F arch=b64 -F uid!=0 -k file_open
This logs all open and openat calls from non-root users on 64-bit systems. The -F arch=b64 restricts to 64-bit architecture (skip this if you run 32-bit binaries).
Why uid!=0? Root opens files constantly; without this filter, you log megabytes per minute on any active server.
Monitor execve (process execution)
auditctl -a exit,always -S execve -F arch=b64 -F uid!=0 -k exec_tracking
Logs every process spawn from non-root. This is high-volume but invaluable for detecting malware execution and understanding attack chains. Each log entry includes the command line, environment, and caller uid.
Monitor network connections
auditctl -a exit,always -S socket -S connect -F arch=b64 -F a0=2 -k network_connect
-F a0=2 filters for IPv4 (address family 2). This catches outbound connections. Pair with firewall logs for full visibility.
Monitor authentication attempts
auditctl -a exit,always -S open -S openat -F dir=/var/log/auth.log -F perm=wa -k auth_log_changes
auditctl -a exit,always -S connect -F a0=2 -S socket -F a2=6 -k ssh_connections
The first catches writes to auth.log (where login attempts are recorded). The second catches TCP connections (a2=6 is the protocol field for TCP). Together they log failed logins and brute-force attempts.
Exclude Rules
Exclude rules prevent audit from logging noisy, low-signal events. They use the never action.
auditctl -a never,exit -S open -S openat -F uid=0 -F dir=/proc -k exclude_proc_root
auditctl -a never,exit -S openat -F uid=1000 -F comm=firefox -k exclude_firefox
These prevent logging root's reads of /proc and Firefox's file opens (common sources of noise). Exclude rules are evaluated first; if a syscall matches an exclude rule, later rules don't apply.
When to exclude: After you've captured enough data to understand the baseline, exclude high-frequency, low-risk syscalls. This keeps your audit log focused and searchable.
Control Rules
Control rules configure the audit daemon itself, not specific events.
auditctl -b 8192
auditctl -r 0
auditctl -l
auditctl -D
-b sets the kernel audit buffer size (in messages). Increase this if you see backlog messages in dmesg.
-r sets the rate limit (messages per second); 0 means unlimited.
-l lists all active rules.
-D deletes all rules (useful for testing; use with care in production).
Persistence and Deployment
Rules loaded via auditctl are ephemeral—they disappear at reboot. To persist them, write to /etc/audit/rules.d/.
cat > /etc/audit/rules.d/custom.rules << 'EOF'
-a exit,always -S open -S openat -F arch=b64 -F uid!=0 -k file_open
-a exit,always -S execve -F arch=b64 -F uid!=0 -k exec_tracking
-w /etc/passwd -p wa -k passwd_changes
-w /etc/sudoers -p wa -k sudoers_changes
EOF
Then load them:
auditctl -R /etc/audit/rules.d/custom.rules
Or enable the audit service to load rules at boot:
sudo systemctl enable auditd
sudo systemctl restart auditd
When This Breaks
High volume kills performance. If you log every file open on a busy server, the audit daemon can't keep up. The kernel drops events, and your logs become incomplete. Start with a few high-value rules, then expand.
Circular buffer fills fast. The default audit log is often small. Monitor /var/log/audit/audit.log size and configure log rotation in /etc/audit/rules.d/audit.rules using the -b and -r flags.
Syscall numbers vary by architecture. A rule that works on x86_64 may fail on ARM. Always include -F arch=b64 (or the appropriate architecture flag) to avoid silent failures.
Excludes are easy to misuse. If you exclude too much, you lose visibility. Test exclude rules in a non-production environment first. If your server is running on shared infrastructure, you may also want to review this guide before making changes that affect your hosting environment.
Audit logs are verbose. A single execve syscall can produce a multi-line log entry. Parse with ausearch or ausparse to extract signal. If you're also monitoring web traffic, the crawl budget implications of exposing audit endpoints are worth keeping in mind:
ausearch -k exec_tracking -ts today | ausparse
One-Line Takeaway
Audit rules are a precision instrument: write file watches for high-value targets, syscall rules for behavior, and exclude rules to cut noise. Test in staging, deploy to production, then tune based on actual volume and false-positive rate.