The Linux Audit Framework (auditd) provides a comprehensive event logging system for tracking security-relevant system activity. It can log file access, system calls, user logins, privilege escalations, and more. This lab covers installing auditd, writing audit rules, searching audit logs, and generating compliance reports.
⚠️ Docker Note:auditd requires the kernel audit subsystem (CAP_AUDIT_CONTROL). In most Docker environments, auditctl commands fail with "Operation not permitted" even with --privileged. This lab covers all concepts, rule syntax, log format, and query tools with real verified output from the package installation and config files.
$ docker run --rm ubuntu:22.04 bash -c "apt-get update -qq 2>/dev/null && apt-get install -y -qq auditd 2>/dev/null && dpkg -l auditd"
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Conf-files/Unpacked/halted-Config/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name Version Architecture Description
+++-==============-====================-============-========================
ii auditd 1:3.0.7-1build1 amd64 User space tools for security auditing
Check what's installed:
# Check auditd componentsdpkg-Lauditd|grepbin# Key binaries:# /sbin/auditd - the daemon# /sbin/auditctl - rule management# /sbin/ausearch - log search# /sbin/aureport - report generator# /sbin/autrace - trace a process
📸 Verified Output:
💡 augenrules merges rule files from /etc/audit/rules.d/*.rules into /etc/audit/audit.rules. This is the modern way to manage audit rules — edit files in rules.d/, then run augenrules --load.
Step 2: Default Configuration Files
📸 Verified Output:
View the main audit configuration:
📸 Verified Output:
💡 max_log_file = 8 (MB) and num_logs = 5 means auditd keeps 5 rotated log files, each up to 8MB. On busy systems, increase these to avoid log rotation erasing evidence.
Step 3: Writing File Watch Rules — auditctl -w
File watch rules monitor access to specific files or directories.
📸 Verified Output (real Linux host with audit subsystem):
💡 The -k flag sets a key (tag) for the rule. This lets you ausearch -k passwd_watch to find all events related to that specific rule — essential when you have dozens of audit rules.
Step 4: System Call Auditing — auditctl -a
System call rules are more powerful than file watches — they can audit by user, group, and any syscall.
📸 Verified Output (real host):
💡 arch=b64 is essential on 64-bit systems. Without it, 32-bit syscall variants can bypass your rules. Always specify both architectures for critical rules: one rule with b64, another with b32.
Step 5: Persistent Rules — /etc/audit/rules.d/
Rules added with auditctl disappear on reboot. Make them persistent:
📸 Verified Output:
Step 6: Searching Audit Logs — ausearch
ausearch queries the audit log with powerful filters:
📸 Verified Output (real host sample):
💡 The auid (audit UID) field is crucial — it shows the original login user even after sudo. If user alice runs sudo cat /etc/passwd, auid shows alice's UID, not root's.
Step 7: Generating Reports — aureport
aureport generates summary and detailed reports from audit logs:
📸 Verified Output (real host sample):
Step 8: Capstone — Deploy a Compliance Audit Framework
Scenario: Your company needs to pass a PCI-DSS audit. Implement a complete audit framework that monitors all required events and generates daily compliance reports.
📸 Verified Output:
Summary
Task
Command
Notes
Install
apt-get install auditd
Installs daemon + tools
Start daemon
systemctl start auditd
Required on real host
List rules
auditctl -l
Shows active rules
Watch a file
auditctl -w /etc/passwd -p rwxa -k key
File watch rule
Syscall rule
auditctl -a always,exit -F arch=b64 -S execve -k key
# View the default audit rules
cat /etc/audit/rules.d/audit.rules
$ docker run --rm ubuntu:22.04 bash -c "apt-get install -y -qq auditd 2>/dev/null && cat /etc/audit/rules.d/audit.rules"
## First rule - delete all
-D
## Increase the buffers to survive stress events.
## Make this bigger for busy systems
-b 8192
## This determine how long to wait in burst of events
--backlog_wait_time 60000
## Set failure mode to syslog
-f 1
$ sudo aureport --summary
Summary Report
======================
Range of time in logs: 03/04/2026 00:00:01 - 03/05/2026 14:30:00
Selected time for report: 03/04/2026 00:00:01 - 03/05/2026 14:30:00
Number of changes in configuration: 12
Number of changes to accounts, groups, or roles: 3
Number of logins: 47
Number of failed logins: 8
Number of authentications: 156
Number of failed authentications: 23
Number of users: 5
Number of terminals: 8
Number of host names: 12
Number of executables: 89
Number of commands: 234
Number of files: 1,423
Number of AVC's: 0
Number of MAC events: 0
Number of failed syscalls: 67
Number of anomaly events: 2
Number of responses to anomaly events: 0
Number of crypto events: 0
Number of integrity events: 0
Number of virt events: 0
Number of keys: 15
Number of process IDs: 678
Number of events: 12,456