697 words
3 minutes
Linux auditd Cheat Sheet

auditd#

Configuration File#

The main configuration file for auditd is located at:

Terminal window
/etc/audit/auditd.conf

This file controls the behavior of auditd itself, including log writing, log rotation, and how auditd responds to disk space shortages or errors.

Terminal window
# Log writing behavior
flush = INCREMENTAL
freq = 20
# Log rotation
num_logs = 5
max_log_file = 6
max_log_file_action = ROTATE
# Dispatcher
disp_qos = lossy
dispatcher = /sbin/audispd
name_format = NONE
# Disk space threshold
space_left = 75
# The "_action" options determine how errors or disk space issues should be handled:
admin_space_left_action = SUSPEND
disk_full_action = SUSPEND
disk_error_action = SUSPEND

Note

  • max_log_file is measured in MB.
  • num_logs only takes effect when max_log_file_action is set to ROTATE.
  • Modern Linux distributions (such as RHEL 9 and Ubuntu 24.04) have integrated the functionality of audispd into auditd. As a result, some systems no longer run a separate audispd process, although the configuration option may still exist for compatibility.

Audit Rules#

Audit Rules can be divided into three categories:

  1. Control Rules — Control the behavior of the Linux Audit Framework.

  2. File Watch Rules (also referred to as File System Rules) — Audit specific files or directories.

  3. System Call Rules — Audit specific system calls.

Modern Linux distributions typically recommend placing custom rules under:

Terminal window
/etc/audit/rules.d/*.rules

Then run:

Terminal window
augenrules --load

to automatically generate and load:

Terminal window
/etc/audit/audit.rules

Although editing audit.rules directly is still supported, using the rules.d directory is the recommended approach because it is easier to maintain and manage.


Example Rules#

Terminal window
# ----------------------------
# Control Rules
# ----------------------------
# Delete all existing rules
-D
# Kernel backlog queue size
## Increase the buffers to survive stress events.
## Make this bigger for busy systems
-b 8192
# Set failure mode
# 0 = silent
# 1 = printk
# 2 = panic
-f 2
# ----------------------------
# File Watch Rules
# ----------------------------
-w /etc/passwd -p wa -k passwd_changes
-w /etc/group -p wa -k group_changes
-w /etc/shadow -p wa -k shadow_changes
-w /etc/sudoers -p wa -k sudoers_changes

Where:

OptionDescription
-wWatch a specific file or directory
-pPermission types (r, w, x, a)
-kAssign a key to the rule for easier searching with ausearch -k

Permission flags:

FlagMeaning
rRead
wWrite
xExecute
aAttribute Change (such as chmod, chown, and touch)

For example:

Terminal window
ausearch -k passwd_changes

Further Reading: What is auditd?#

In Linux, almost every security-related operation is ultimately handled by the Kernel.

For example:

  • User login or logout
  • Running sudo
  • Executing a program
  • Modifying /etc/passwd
  • Changing file permissions (chmod)
  • Deleting files
  • Creating new processes

These operations are eventually translated into one or more System Calls, which are processed by the Linux Kernel.

To support security auditing and compliance requirements, the Linux Kernel provides a built-in Linux Audit Framework that records security-related events.

auditd (Linux Audit Daemon) is the userspace daemon that works with this framework.

Its responsibilities include:

  • Receiving Audit Events generated by the Kernel

  • Writing events to /var/log/audit/audit.log

  • Managing log rotation

  • Forwarding events to other plugins or logging systems (such as rsyslog or a SIEM platform)

The workflow can be summarized as follows:

System Call / File Change
Linux Kernel (Audit Framework)
Generate Audit Event
auditd
/var/log/audit/audit.log

In general, the process works like this:

  1. The administrator loads Audit Rules.

  2. The Linux Kernel monitors system activity according to those rules.

  3. When a rule is matched, the Kernel generates an Audit Event.

  4. auditd receives the event and writes it to /var/log/audit/audit.log.

  5. Administrators use tools such as ausearch and aureport to search or analyze the logs.

The responsibilities of each component are summarized below:

ComponentFunction
Linux Audit FrameworkA kernel subsystem that generates Audit Events based on configured Audit Rules.
auditdReceives Audit Events and writes them to audit logs.
auditctlDynamically manages Audit Rules stored in the Kernel.
augenrulesMerges and loads rules from /etc/audit/rules.d/.
ausearchSearches Audit Logs based on specified criteria.
aureportGenerates summary reports from Audit Logs.

Understanding this architecture makes it easier to explain several common behaviors.

For example:

  • Why do changes made with auditctl take effect immediately?

    • Because auditctl updates the Audit Rules stored in the Kernel directly, rather than modifying configuration files.
  • Why do rules disappear after a reboot?

    • Because rules added with auditctl exist only in memory. They must be reloaded from configuration files after the system starts.
  • Why can the Kernel continue generating Audit Events even if auditd is stopped?

    • Because auditing is performed by the Linux Kernel. Without auditd, there is simply no userspace daemon available to receive and write those events to disk.

A simple way to remember the Linux Audit System is:

Audit Rules tell the Kernel what to monitor; the Kernel detects events; auditd records them; and tools like ausearch and aureport help you analyze them.

Linux auditd Cheat Sheet
https://blog.drcharon.com/en/posts/auditd-note/
Author
Charon
Published at
2024-07-25
License
CC BY-NC-SA 4.0