How to Use Ubuntu auditd to Configure Forensic File System Monitoring

The Blindness of Traditional Logging

When an Ubuntu server is compromised by an insider threat, the damage is usually silent. Suppose a junior systems administrator, acting maliciously, decides to copy the highly sensitive /etc/shadow file (which contains all the hashed passwords) to a USB drive, and then edits the /etc/ssh/sshd_config file to open a backdoor port.

Standard Linux logging (via syslog or journalctl) is fundamentally blind to these actions. By default, Linux does not log when a user simply opens and reads a file, nor does it log which specific user opened a configuration file in nano or vim. By the time the security team realizes the server has a backdoor, they have zero mathematical proof regarding who created it, when it was created, or how the data was exfiltrated.

To eliminate this blindness, enterprise security engineers deploy the Linux Audit Daemon (auditd). auditd operates deep within the Linux kernel. It hooks directly into the system call (syscall) architecture. This means auditd does not rely on applications to report their activity. It mathematically intercepts every single interaction between the userspace and the filesystem. You can program auditd to trigger a forensic alert the exact millisecond any user—even the root user—attempts to read, write, or execute a specific file, providing an irrefutable, cryptographically secure audit trail.

Step 1: Installing the Audit Subsystem

auditd is a core component of the Linux security architecture, but it is not always enabled by default on minimal Ubuntu server installations.

Install the daemon and its core utilities:

sudo apt update
sudo apt install auditd audispd-plugins -y

Once installed, the daemon starts automatically and begins logging basic security events (like SSH logins and sudo escalations) to its dedicated, highly restricted log file: /var/log/audit/audit.log.

Step 2: Defining Forensic Watch Rules

The true power of auditd is the ability to write custom “Watch Rules.” A Watch Rule tells the kernel to monitor a specific file or directory and log an event if a specific permission is requested.

You define rules using the auditctl command. Suppose you want to forensically track any user who attempts to modify the /etc/ssh/sshd_config file.

sudo auditctl -w /etc/ssh/sshd_config -p wa -k sshd_tampering

Decoding the Logic:

  • -w /etc/ssh/sshd_config: The Watch target (the absolute file path).
  • -p wa: The Permissions to monitor. w stands for Write, and a stands for Attribute change (e.g., someone running chmod). If someone just reads (r) the file, it will not trigger.
  • -k sshd_tampering: The Key. This is a custom string you define. When searching millions of lines of logs later, this tag allows you to instantly filter for this specific event.

Step 3: Monitoring for Data Exfiltration (Read Tracking)

Now let’s track the malicious insider attempting to steal the password hashes.

You write a rule targeting the /etc/shadow file. But this time, you must monitor for Read (r) access, because stealing a file does not require modifying it.

sudo auditctl -w /etc/shadow -p rwa -k shadow_breach

If a user types cat /etc/shadow or tries to copy it using cp /etc/shadow ~/stolen_data.txt, the kernel instantly intercepts the open() system call, records the exact user ID who requested the read, logs the event, and then allows the action to proceed.

Step 4: Making the Rules Persistent

Like iptables, commands injected via auditctl are entirely volatile. If you reboot the Ubuntu server, all your forensic tripwires vanish.

To make them permanent, you must write the rules into the master configuration file located at /etc/audit/rules.d/audit.rules.

Open the file in a text editor and append the exact arguments (without the auditctl prefix):

-w /etc/ssh/sshd_config -p wa -k sshd_tampering
-w /etc/shadow -p rwa -k shadow_breach

Restart the daemon to fuse the rules into the kernel:

sudo systemctl restart auditd

Step 5: Interrogating the Forensic Logs (ausearch)

If you open /var/log/audit/audit.log using cat or nano, you will see a chaotic, illegible mess of hexadecimal memory addresses, system call numbers, and raw epoch timestamps.

You must use the ausearch (Audit Search) utility to translate the binary data into human-readable forensic intelligence.

To search for the malicious insider who triggered the SSH tampering rule, use the -k (Key) flag you defined earlier:

sudo ausearch -k sshd_tampering -i

(Note: The -i flag instructs ausearch to Interpret the data, translating epoch timestamps into local time and resolving numerical User IDs back into actual usernames).

The output will definitively prove the breach. It will show the exact time the file was modified, the name of the file (/etc/ssh/sshd_config), the exact exe (executable) used to modify it (e.g., /usr/bin/nano), and the uid (e.g., jdoe) of the user who executed the command. Because auditd records the original auid (Audit User ID), even if jdoe used sudo to switch to the root user, the audit log pierces the disguise and records that jdoe was the original human who logged into the terminal.

Conclusion

Depending on standard application logging to detect insider threats and privilege escalation leaves the enterprise exposed to massive forensic blind spots. By mastering the auditd subsystem, Ubuntu engineers deploy kernel-level surveillance. The ability to mathematically monitor specific files for read/write access, tag events with searchable cryptographic keys, and definitively trace actions back to the original login ID ensures that every single filesystem interaction is permanently recorded in an irrefutable chain of evidence.

RELATED POSTS

  • How to Configure Network Teaming (Bonding) in Ubuntu Server
  • How to Install and Configure the Postfix Mail Server on Ubuntu
  • How to Join an Ubuntu Linux Machine to a Windows Active Directory Domain using SSSD
  • How to Install and Configure the Proxmox Backup Server (PBS) Client on Debian
  • How to Configure a Chroot Jail for SFTP Users on Ubuntu 22.04
  • Get the best tech tips delivered straight to your inbox.

    Join thousands of readers mastering Apple, Google, Microsoft, and Linux.