Skip to content
Log In Sign Up info@muvcloud.com

What auditd Records

The kernel checks every event against a list of audit rules. When one matches, it sends a record to auditd, which writes it to /var/log/audit/audit.log. A record includes the time, the program, the user ID, and the login user ID (auid), which stays the same after sudo or su. That is what makes the audit log useful: a change made as root can still be traced to the person who logged in.

auditd does not block anything. It records what happened. Blocking is the job of permissions, SELinux, and the firewall; see what is SELinux.

Install and Check the Status

On Ubuntu and Debian:

sudo apt install auditd
sudo systemctl enable --now auditd

On AlmaLinux and Rocky Linux the audit package is normally installed and running already; if not, install it with sudo dnf install audit. Check with:

sudo systemctl status auditd
sudo auditctl -s
sudo auditctl -l

auditctl -s shows whether auditing is enabled; auditctl -l lists the rules loaded now. The auditd unit refuses a manual stop through systemctl, so systemctl stop and systemctl restart fail. Loading rules needs no restart. On AlmaLinux and Rocky Linux, Red Hat documents sudo service auditd restart for the times you do need one.

Watch a File

Add a watch at runtime to try it out. This records writes and attribute changes to /etc/passwd under a key you choose:

sudo auditctl -w /etc/passwd -p wa -k passwd_changes
  • -w: the file or directory to watch. A directory is watched recursively.
  • -p: the access types: r read, w write, x execute, a attribute change.
  • -k: a key, so you can find the records later.

The auditctl manual marks this -w form as deprecated for performance reasons, though it still works. The same watch in the recommended syscall form:

sudo auditctl -a always,exit -F arch=b64 -F path=/etc/passwd -F perm=wa -k passwd_changes

Use -F dir= instead of -F path= to watch a directory tree. Rules added with auditctl are lost at reboot. That makes it the safe place to test a rule before you save it.

A System Call Rule

System call rules catch actions anywhere on the system. This one records file deletions and renames by logged-in users on a 64-bit server:

sudo auditctl -a always,exit -F arch=b64 -S unlink,unlinkat,rename,renameat \
  -F auid>=1000 -F auid!=unset -k file_delete

Broad rules such as recording every executed command can produce a large log quickly. Start narrow, watch the log size for a day, and widen only if you need to.

Make Rules Persistent

Once a rule does what you want, save it in a file under /etc/audit/rules.d/, for example /etc/audit/rules.d/50-local.rules, without the auditctl word:

-a always,exit -F arch=b64 -F path=/etc/passwd -F perm=wa -k passwd_changes
-a always,exit -F arch=b64 -F path=/etc/ssh/sshd_config -F perm=wa -k sshd_config
-a always,exit -F arch=b64 -F path=/etc/sudoers -F perm=wa -k sudoers

Check the files, then load them:

sudo augenrules --check
sudo augenrules --load
sudo auditctl -l

augenrules merges the files in rules.d into /etc/audit/audit.rules, which is read at boot. A line with -e 2 at the end makes the rules immutable until the next reboot; leave it out until your rule set is final, since even root cannot change the rules afterward.

Search the Log with ausearch

sudo ausearch -k passwd_changes -i
sudo ausearch -k sshd_config -ts today -i

-i turns numeric IDs into user names and syscall names. -ts sets a start time, such as today, recent, or a date.

Summaries with aureport

CommandShows
aureport --summaryTotals by event type
aureport -kEvents by rule key
aureport -auAuthentication attempts
aureport -lLogins
aureport -fFile events

Log Size and Rotation

auditd rotates its own log; logrotate is not used for it. The settings are in /etc/audit/auditd.conf:

  • max_log_file: the size of one log file in megabytes.
  • num_logs: how many rotated files to keep.
  • max_log_file_action: what to do when a file is full, usually ROTATE.
  • space_left_action: what to do when the disk is nearly full.

Do not delete audit logs by hand; lower the limits and let auditd rotate. Where other logs live is covered in Linux log files location, and a periodic security check of the whole server is described in Lynis.

Updated:

Linux VPS with Full Root Access

MUVCloud cloud servers run on KVM with Enterprise NVMe SSD storage and full root access, in Turkey, the Netherlands, and the USA.

Cloud VPS Plans Starting at2.99 $/mo Cheap Linux VPS

No Limits on Service or Support

You are not on your own as your projects grow. Our support engineers are ready 24/7, on several channels, whenever you need them.

Support specialist
  • 100% customer satisfaction goal
  • Our own hardware
  • 24/7 ticket and email support
  • 4 countries with locations