auditd on Linux servers: rules that matter and how to check them
Set up the Linux audit daemon on Debian, Ubuntu and RHEL with a small rule set, prove each rule fires, read the results with ausearch and aureport, and get the log off the host.
auditd is the user-space half of the Linux audit system. The kernel checks every system call against the rules you load and hands matching events to auditd, which writes them to /var/log/audit/audit.log. Because the records come from the kernel, they show what actually happened, such as which file was written and by which program, whether or not the program logged anything itself.
It is not an alerting tool. auditd records; it doesn’t tell anyone. This guide sets up a small rule set you can live with, shows how to check that each rule fires, and covers the parts that differ between Debian 13, Ubuntu 24.04 and RHEL 9 and 10.
Install it and check it is running
sudo apt install auditd # Debian, Ubuntu
sudo dnf install audit # RHEL family (usually already installed)
sudo auditctl -sOn RHEL, auditd is part of a minimal install and is enabled by default. In the auditctl -s output, enabled 1 means auditing is on, and lost is the number of events the kernel dropped because the queue was full. Keep an eye on lost; it should stay at 0. Red Hat: Auditing the system ↗
The audit userspace changed in version 4.0, and the distributions are split across that line:
| Debian 13 | Ubuntu 24.04 | RHEL 9 | RHEL 10 | |
|---|---|---|---|---|
| audit version | 4.0 | 3.1 | 3.1 | 4.0, later 4.2 |
| Rules loaded by | audit-rules.service | auditd.service | auditd.service | audit-rules.service |
| Restart with | systemctl restart auditd | systemctl restart auditd | service auditd restart | service auditd restart |
| Sample rules | /usr/share/doc/auditd/examples/audit-rules/ | /usr/share/doc/auditd/examples/rules/ | /usr/share/audit/sample-rules/ | /usr/share/audit-rules/ |
The restart difference trips people up. Upstream’s unit file sets RefuseManualStop=yes, so on RHEL systemctl stop and restart are refused. Red Hat says to use the service command so that the auid of the person doing it is recorded. Debian and Ubuntu patch that setting out so the package can restart the daemon on upgrade. Debian patch ↗ audit ChangeLog ↗
Where rules live
Put your rules in files under /etc/audit/rules.d/ ending in .rules. augenrules merges them in sorted order into /etc/audit/audit.rules, which is what gets loaded at boot. Don’t edit audit.rules directly: the next merge overwrites it. augenrules(8) ↗
ls /etc/audit/rules.d/
sudo auditctl -l # the rules the kernel has right nowIf you add rules and nothing is ever recorded, look for a -a never,task line in auditctl -l. Some distributions, Fedora among them, ship a rule like that to turn syscall auditing off by default, and it overrides everything after it.
A starting rule set
The temptation is to load a long compliance rule set and walk away. Every syscall rule is checked on every system call by every program, so a long list slows the machine down and fills the disk with records nobody reads. Start with the changes an intruder makes to keep access, and the commands people run.
# /etc/audit/rules.d/50-server.rules
# accounts and privileges
-a always,exit -F arch=b64 -F path=/etc/passwd -F perm=wa -k identity
-a always,exit -F arch=b64 -F path=/etc/shadow -F perm=wa -k identity
-a always,exit -F arch=b64 -F path=/etc/group -F perm=wa -k identity
-a always,exit -F arch=b64 -F path=/etc/sudoers -F perm=wa -k sudoers
-a always,exit -F arch=b64 -F dir=/etc/sudoers.d -F perm=wa -k sudoers
# SSH configuration and root's keys
-a always,exit -F arch=b64 -F path=/etc/ssh/sshd_config -F perm=wa -k sshd
-a always,exit -F arch=b64 -F dir=/etc/ssh/sshd_config.d -F perm=wa -k sshd
-a always,exit -F arch=b64 -F dir=/root/.ssh -F perm=wa -k root_keys
# places used to persist
-a always,exit -F arch=b64 -F path=/etc/crontab -F perm=wa -k cron
-a always,exit -F arch=b64 -F dir=/etc/cron.d -F perm=wa -k cron
-a always,exit -F arch=b64 -F dir=/var/spool/cron -F perm=wa -k cron
-a always,exit -F arch=b64 -F dir=/etc/systemd/system -F perm=wa -k systemd
# kernel modules
-a always,exit -F arch=b64 -S init_module -S finit_module -S delete_module -k modules
# commands run by people who logged in
-a always,exit -F arch=b64 -S execve -F auid>=1000 -F auid!=unset -k exec
-a always,exit -F arch=b32 -S execve -F auid>=1000 -F auid!=unset -k execA few things about this file:
- The file rules use the syscall form instead of the older -w /etc/shadow -p wa. The auditctl man page calls the -w form deprecated “due to poor system performance”. Many guides, including Red Hat’s, still use it.
- perm=wa records writes and attribute changes (ownership, permissions), not reads. dir= covers everything under that directory.
- Each rule names its architecture. The man page says to supply one for best performance. A syscall rule without one applies to both 32-bit and 64-bit calls, and auditctl warns about it. That’s why the execve rule appears twice.
- auid is the login UID. It is set when someone logs in and stays the same through sudo and su, so an exec record shows who really ran the command. auid!=unset leaves out daemons, which never logged in, and auid>=1000 matches normal user accounts.
- The exec rules are by far the noisiest part. They are also the most useful after an incident. If the volume is too much, keep them and remove something else.
- Direct root logins have auid 0 and fall outside the exec rule. Turning those logins off is the better fix.
Root logins and the rest of the SSH settings are covered in the SSH hardening guide. SSH hardening → auditctl(8) ↗ audit.rules(7) ↗
On a Docker host, add the same kind of rule for /etc/docker. The kernel audit system is not aware of containers: syscalls made inside a container are checked against the host’s rules and land in the host’s log. One catch from the audit maintainers is that executable paths are seen from inside the container, so exe= filters written for host paths won’t match container processes. audit-kernel issue 145 ↗
Load the rules and prove they fire
sudo augenrules --check
sudo augenrules --load
sudo auditctl -l | grep -c .The count should match the number of rules you wrote plus any the distribution ships. Then cause an event you expect to be recorded, and look for it:
sudo useradd audittest && sudo userdel audittest
sudo ausearch -k identity --start recent -iYou should see records for writes to /etc/passwd and /etc/shadow, with your own user in the auid field even though the command ran through sudo. If nothing comes back, check auditctl -l for the rule and auditctl -s for enabled 1.
Audit from the moment the kernel starts
Processes that start before auditd aren’t audited unless the kernel is told to audit from boot. With audit=1, the kernel holds events in memory until auditd starts. The default queue is only 64 events, so raise it at the same time. Kernel parameters ↗
# Debian, Ubuntu: add to GRUB_CMDLINE_LINUX in /etc/default/grub, then
sudo update-grub
# RHEL
sudo grubby --update-kernel=ALL --args="audit=1 audit_backlog_limit=8192"
# after a reboot
cat /proc/cmdlineRead the log with ausearch and aureport
audit.log is hard to read raw. ausearch finds records and -i turns numeric IDs, syscalls and hex-encoded values into names. aureport summarises. ausearch(8) ↗ aureport(8) ↗
sudo ausearch -k sshd --start today -i # changes to SSH config today
sudo ausearch -k exec -ua 1001 --start today -i # what user 1001 ran
sudo aureport --summary # counts by event type
sudo aureport -au --failed # failed authentications
sudo aureport -l # logins
sudo aureport -k --summary # events per rule key
sudo aureport -x --summary # most-run programsaureport -k --summary is a good weekly habit. A key with no events at all usually means a rule is wrong. A key with millions points to the rule that is eating your disk.
Size the log for the history you need
The shipped /etc/audit/auditd.conf keeps five files of 8 MiB each and rotates them, so you get about 40 MiB of history. With exec rules on a busy server that can be a few days. When the disk fills, the shipped disk_full_action is SUSPEND: auditd stops writing, and the gap is easy to miss. auditd.conf(5) ↗
sudo grep -E "^(max_log_file|num_logs|max_log_file_action|space_left_action|disk_full_action) " /etc/audit/auditd.confRaise max_log_file and num_logs until the history covers the period you need, then restart auditd using the command for your distribution from the table above. Red Hat’s documentation lists stricter choices for systems where losing audit records is unacceptable, such as halting when the disk is full.
Get the records off the server
Anyone who gets root on the server can edit or delete /var/log/audit. Records that matter have to leave the host as they’re written. The simplest route is the syslog plugin, which hands each event to the local syslog daemon so it travels with your other logs:
# RHEL only: the plugin is in a separate package
sudo dnf install audispd-plugins
# all: set active = yes in the plugin config
sudo sed -i "s/^active = no/active = yes/" /etc/audit/plugins.d/syslog.conf
sudo systemctl restart auditd # service auditd restart on RHELTo check, repeat the useradd test and confirm the records arrive wherever your logs are collected. For auditd-to-auditd forwarding there is also audisp-remote, in the audispd-plugins package on every distribution.
Lock the rules when you’re done
Once the rules have settled, -e 2 as the very last rule locks the audit configuration. From then on, any attempt to change it is denied and recorded, and the only way to change the rules is to reboot. An intruder can’t quietly turn auditing off, but neither can you, so leave this until last.
# /etc/audit/rules.d/99-finalize.rules
-e 2After the next augenrules --load or reboot, auditctl -s shows enabled 2.
auditd and SOC 2
SOC 2’s common criteria include CC7.2: the entity “monitors system components and the operation of those components for anomalies that are indicative of malicious acts”, and the anomalies are analysed to decide whether they are security events. Audit records of account changes, privilege changes and admin commands are good evidence of the monitoring half. Auditors usually also ask how the records are reviewed and how long they are kept, which is why forwarding and log sizing matter as much as the rules. AICPA Trust Services Criteria ↗
Review is where auditd leaves the work to you. A host-based intrusion detection system does that part: it turns host activity into alerts someone reads. Vigilhold, our host agent for Linux servers, watches logins, processes, connections and file changes on every server. Its Business plan’s compliance reports give your auditor evidence for SOC 2 and other frameworks. They are not a certification. What a HIDS does → See Vigilhold →
The short version
| Step | Check it worked |
|---|---|
| auditd running | auditctl -s shows enabled 1 and lost 0 |
| Rules loaded | auditctl -l lists your rules |
| Rules fire | ausearch -k identity finds the useradd test, with your auid |
| Audit from boot | /proc/cmdline contains audit=1 |
| Enough history | The oldest audit.log covers the period you need |
| Off the host | The test event shows up in your central logs |
| Locked | auditctl -s shows enabled 2 |