Introduction
The Linux Audit Daemon (auditd) is a powerful security tool that allows system administrators to monitor and record system events. It operates at the kernel level, providing deep visibility into system calls, file access, and command execution. This makes it an essential component for security auditing, compliance, and troubleshooting.
Compared with ordinary logs, auditd sits closer to the operating system's decision point. That is why it can answer questions such as which user account accessed a sensitive file or which process performed a privileged action. In security operations, this low-level trace is especially useful when normal application logs are incomplete or easy to tamper with.
In this lab, you will learn the basics of system auditing using auditd. You will start by verifying the service status, then move on to configuring custom audit rules to monitor specific files and directories. Finally, you will learn how to extract and interpret the generated audit logs using the ausearch utility. By the end of this lab, you will have a solid foundation in tracking user activities and securing sensitive data on a Linux system.
Check Auditd Service Status
In this step, you will verify that the Linux Audit Daemon (auditd) is installed and running correctly on your system. The auditd service is responsible for writing audit records to the disk.
Checking service state first is a good operational habit. Many security tools fail quietly from the user's perspective: the machine still works, but the evidence pipeline is broken. Before trusting any monitoring system, verify that the data source is actually alive and recording.
First, let's check the status of the auditd service using the systemctl command. This command interacts with the systemd system and service manager.
Run the following command in your terminal:
sudo systemctl status auditd
You should see output indicating that the service is active and running. The output will look similar to this:
● auditd.service - Security Auditing Service
Loaded: loaded (/lib/systemd/system/auditd.service; enabled; vendor preset: enabled)
Active: active (running) since Thu 2026-03-05 13:58:28 CST; 4min 26s ago
Docs: man:auditd(8)
https://github.com/linux-audit/audit-documentation
Main PID: 2857 (auditd)
Tasks: 2 (limit: 4217)
Memory: 512.0K
CPU: 45ms
CGroup: /system.slice/auditd.service
└─2857 /sbin/auditd
Press q to exit the status view if it does not return to the command prompt automatically.
Next, you can use the auditctl command to check the current status of the audit system directly from the kernel's perspective. The -s flag stands for status.
sudo auditctl -s
The output will display various configuration parameters of the audit system:
enabled 1
failure 1
pid 2857
rate_limit 0
backlog_limit 8192
lost 0
backlog 0
backlog_wait_time 60000
backlog_wait_time_actual 0
loginuid_immutable 0 unlocked
The enabled 1 line confirms that the auditing system is currently active and recording events.
Configure Audit Rules for Files
In this step, you will learn how to create custom audit rules to monitor access to specific files. We will use the auditctl command to add a temporary rule that watches the /etc/passwd file, which contains user account information.
Choosing what to audit is an engineering tradeoff. Auditing everything would create huge volumes of noisy records. Auditing nothing leaves you blind. Sensitive identity files such as /etc/passwd are a good starting point because they are high value and change relatively infrequently, so suspicious modifications stand out.
The auditctl command is used to control the audit system and configure rules. To watch a file, we use the -w flag followed by the file path. We also need to specify what type of access we want to monitor using the -p flag (permissions), and we can assign a custom key using the -k flag to make searching the logs easier later.
Run the following command to monitor the /etc/passwd file for write (w) and attribute change (a) operations:
sudo auditctl -w /etc/passwd -p wa -k passwd_changes
Let's break down the command:
-w /etc/passwd: Tells the audit system to watch the/etc/passwdfile.-p wa: Specifies the permissions to monitor.wstands for write, andastands for attribute change (like changing permissions or ownership).-k passwd_changes: Assigns the custom keypasswd_changesto any log entries generated by this rule.
To verify that your rule has been successfully added, you can list all active audit rules using the -l flag:
sudo auditctl -l
You should see your newly created rule in the output:
-w /etc/passwd -p wa -k passwd_changes
Now, let's trigger the rule by simulating an attribute change. We can use the touch command to update the timestamp of the /etc/passwd file, which counts as an attribute change.
sudo touch /etc/passwd
This action has now been recorded by the auditd service in the background. We will learn how to view this record in a later step.
Monitor Directory Access
In addition to individual files, auditd can also monitor entire directories. This is particularly useful for protecting sensitive data folders where you want to know if anyone reads, modifies, or executes files within them.
Directory-level monitoring broadens the question from "was this one file touched?" to "is anything in this sensitive area being accessed?" That is useful during investigations because attackers often explore a directory before they know the exact file they want. Watching the whole area captures that broader behavior.
During the environment setup, a directory named sensitive_dir was created in your ~/project folder. In this step, you will configure an audit rule to monitor any read access to this directory.
Run the following command to watch the directory for read (r), write (w), and attribute (a) access:
sudo auditctl -w /home/labex/project/sensitive_dir -p rwa -k sensitive_access
Notice that we included r in the permissions flag this time. This means that even simply viewing the contents of a file inside this directory will trigger an audit log entry.
Verify that the new rule has been added to the list of active rules:
sudo auditctl -l
Your output should now display both rules:
-w /etc/passwd -p wa -k passwd_changes
-w /home/labex/project/sensitive_dir -p rwa -k sensitive_access
Now, let's trigger this new rule by reading the secret file located inside the sensitive directory. Use the cat command to view its contents:
cat /home/labex/project/sensitive_dir/secret.txt
You will see the contents of the file printed to the terminal:
Highly confidential data
Because you read a file inside the monitored directory, auditd has generated a new log entry tagged with the sensitive_access key.
Search Audit Logs with ausearch
Now that you have configured audit rules and triggered them by interacting with the monitored files and directories, it is time to view the generated logs. The raw audit logs are stored in /var/log/audit/audit.log, but reading them directly can be difficult due to their complex format.
To make searching and interpreting logs easier, Linux provides the ausearch utility. You can use ausearch to filter logs based on various criteria, such as the custom keys we defined earlier.
Let's search for the events related to the /etc/passwd file using the key passwd_changes:
sudo ausearch -k passwd_changes
You will see a detailed log entry similar to this:
----
time->Thu Mar 5 14:03:16 2026
type=PROCTITLE msg=audit(1772690596.413:254): proctitle=746F756368002F6574632F706173737764
type=PATH msg=audit(1772690596.413:254): item=1 name="/etc/passwd" inode=667375 dev=fc:03 mode=0100644 ouid=0 ogid=0 rdev=00:00 nametype=NORMAL cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0
type=PATH msg=audit(1772690596.413:254): item=0 name="/etc/" inode=654081 dev=fc:03 mode=040755 ouid=0 ogid=0 rdev=00:00 nametype=PARENT cap_fp=0 cap_fi=0 cap_fe=0 cap_fver=0 cap_frootid=0
type=CWD msg=audit(1772690596.413:254): cwd="/home/labex/project"
type=SYSCALL msg=audit(1772690596.413:254): arch=c000003e syscall=257 success=yes exit=3 a0=ffffff9c a1=7ffc30302bb6 a2=941 a3=1b6 items=2 ppid=3593 pid=3594 auid=1000 uid=0 gid=0 euid=0 suid=0 fsuid=0 egid=0 sgid=0 fsgid=0 tty=pts5 ses=1 comm="touch" exe="/usr/bin/touch" subj=unconfined key="passwd_changes"
Here are some important fields to understand:
time: The exact date and time the event occurred.syscall: The system call that triggered the event (e.g., opening a file).success=yes: Indicates whether the operation was successful.auid: The Audit User ID. This is the original ID of the user who logged in, which remains the same even if they switch to therootuser usingsudo. This is crucial for tracking accountability.uid: The User ID under which the command was executed (0 means root).comm: The command that was executed (in this case,touch).exe: The absolute path to the executable.
Next, search for the events related to the sensitive directory using the sensitive_access key:
sudo ausearch -k sensitive_access
You will see a similar log entry, but this time the comm field will show cat, and the exe field will point to /usr/bin/cat, reflecting the action you took in the previous step.
By using custom keys and ausearch, you can quickly pinpoint exactly who accessed what and when, making auditd an invaluable tool for system security.
Summary
In this lab, you explored the fundamentals of system auditing using the Linux Audit Daemon (auditd). You started by verifying the status of the auditd service to ensure it was actively monitoring the system. You then learned how to use auditctl to create custom watch rules for specific files and directories, assigning unique keys to categorize the events. Finally, you utilized the ausearch command to query the audit logs, allowing you to track exactly which commands were executed and identify the original user responsible for the actions. These skills are essential for maintaining security, accountability, and compliance on Linux systems.



