When a configuration file’s modification time changes but the service’s behavior cannot be reproduced, shell history alone cannot establish who made the change or how. An editor may replace the original file with a temporary one, and automation may run without an interactive terminal. Tracing changes on a dedicated server requires recording file operations, the processes that perform them, and login identities, then using a repeatable test to verify that the records are complete.
1. Define the audit scope and identity requirements
This article uses Debian 12 and tests auditd in a separate lab directory without changing production configuration. Debian 12 is one of TermAMD’s free OS options; after payment, retrieve the credentials from the control panel and connect over SSH. Run the experiment from a regular account with sudo privileges, not from a background process whose originating login session cannot be identified.
auditd receives kernel audit events, but it does not automatically determine whether a change was approved. Rules collect the data; tickets or change records explain the purpose. Correlate the two using timestamps and identities.
File audit records are neither content backups nor tamper-proof storage. An operator with administrative privileges may affect the collection chain. Export important evidence separately and restrict access to it.
First, install the components and check the current state:
sudo apt-get update
sudo apt-get install auditd
sudo systemctl enable --now auditd
sudo auditctl -s
sudo auditctl -l
cat /proc/self/loginuid
An enabled value of 1 means auditing is configurable; 2 means the rules are locked and cannot be added or removed at runtime. If the rules are locked, stop the experiment and follow the existing change-management process rather than attempting to bypass the lock. A loginuid value of 4294967295 means the identity is unset, so subsequent events cannot serve as complete evidence of an individual’s actions.
Also record the initial lost value. Even if the target events are found, an increase in the lost-event counter means you cannot claim that records for that period are complete.
2. Watch the directory to capture file replacement
Watching a single file can miss the way an editor actually writes changes. This experiment watches a dedicated directory so that writes, attribute changes, and renames within it fall under the same search scope. The directory must exist before the rule is loaded.
sudo install -d -m 0750 /srv/audit-lab
printf 'mode=before\n' | sudo tee /srv/audit-lab/app.conf >/dev/null
sudo auditctl -w /srv/audit-lab -p wa -k change_lab
sudo auditctl -l
w watches write operations, while a watches attribute changes; change_lab is a search key, not an access-control policy. File-watch syntax is convenient for small-scale testing. For larger deployments, evaluate syscall-based rules and their performance overhead.
Do not watch the entire root directory. Start with a few configuration paths, excluding caches, continuously written data, and build directories. Otherwise, event volume can obscure the changes you actually need to trace.
Directory watches also have filesystem boundaries: do not assume a rule automatically covers filesystems mounted separately beneath the watched directory. If the production configuration spans mount points, identify and test each one separately.
3. Perform three types of operation and correlate by event ID
Test writing, replacement, and deletion separately
The following commands affect only the lab files. The first step overwrites the contents, the second simulates writing a temporary file and renaming it into place, and the third checks that deletion is recorded.
sudo sh -c 'printf "mode=direct\n" > /srv/audit-lab/app.conf'
sudo sh -c 'printf "mode=replaced\n" > /srv/audit-lab/app.conf.new'
sudo mv /srv/audit-lab/app.conf.new /srv/audit-lab/app.conf
sudo rm /srv/audit-lab/app.conf
sudo ausearch -k change_lab -ts recent -i
If the search returns no results, first recheck that the rule exists, the commands succeeded, and collection is functioning. Do not immediately broaden the watch scope. recent searches a recent period; it is not a substitute for an incident’s precise time range.
A single audit event may contain several records, including SYSCALL, PATH, CWD, and PROCTITLE. Read them together using the timestamp and event serial number in msg=audit(...). Do not count each line as a separate change.
Cross-check identities and execution results
Focus on these fields:
auid: the audit login identity, which usually persists after privilege escalation through sudo.uid,euid: the process user identity and effective user identity, which explain the privileges actually used.exe,comm: clues about the program executed, not a complete explanation of its operational purpose.success,exit: whether the operation succeeded. A path appearing in a record does not by itself prove that a change completed.- Names and
nametypevalues inPATH: help distinguish creation, deletion, and the multiple paths involved in a rename.
Validation should account for all three operation types, confirm that the replacement event includes the relevant paths, and explain the difference between the login identity and the elevated identity. A shared account can only be traced to that shared identity; auditd cannot automatically distinguish the people using it.
4. Check rule ownership before making rules persistent
A rule active at runtime is not necessarily persistent across reboots. First confirm that this host uses augenrules to manage rules. If a configuration-management tool is already in place, put the new rule under the same ownership so that manual files and automated deployments do not overwrite each other.
printf '%s\n' '-w /srv/audit-lab -p wa -k change_lab' |
sudo tee /etc/audit/rules.d/70-change-lab.rules >/dev/null
sudo chmod 0600 /etc/audit/rules.d/70-change-lab.rules
sudo augenrules --check
sudo less /etc/audit/audit.rules
--check only checks whether the rule sources require regeneration; it does not validate syntax or behavior. Before loading, inspect the other rule files as well, especially directives that clear rules, disable collection, or finally lock the rules.
Once you have confirmed that the complete rule set can be reloaded, run:
sudo augenrules --load
sudo auditctl -l
sudo auditctl -s
Loading applies to the entire rule set, rather than merely appending this file. If loading fails, do not assume the previous state is restored automatically. Preserve the existing rules and their sources beforehand, then repeat all three operation types after loading. After an authorized reboot test, also check that the rules and events are still present. Writing the file to disk is not sufficient to consider the work complete.
5. Export evidence and remove only the lab configuration
Preserve the original numeric fields when exporting so they can later be analyzed against the account mappings in effect at the time. -i is useful for reading records during an investigation, but account names can change, so do not retain only the interpreted version.
sudo install -d -m 0700 /var/lib/audit-evidence
sudo sh -c 'umask 077; ausearch -k change_lab -ts today --raw > /var/lib/audit-evidence/change-lab.raw'
sudo sha256sum /var/lib/audit-evidence/change-lab.raw
sudo auditctl -s
Also record the search range, host identifier, rule text, and the before-and-after lost values. A checksum can help detect changes after export; it cannot prove that nobody interfered during collection. Logs may contain paths and command arguments, so handle them as sensitive operational data.
At the end of the experiment, remove the persistent rule source first, then delete the specific runtime rule:
sudo rm /etc/audit/rules.d/70-change-lab.rules
sudo auditctl -W /srv/audit-lab -p wa -k change_lab
sudo augenrules
sudo auditctl -l
sudo rmdir /srv/audit-lab
The final augenrules command regenerates the rules file without --load, avoiding another reload of the entire rule set just to clean up the experiment. Do not use a global rule-clearing command, and do not delete the audit logs.
A production deployment is not complete merely because “the service is running.” The rule scope must be clear, all three operation types must be recorded, the login identity must be explainable, the lost-event counter must not have increased, and removal must affect only the intended rule. Restoring file contents remains the job of version history and backups.
Frequently asked questions
Can auditd identify the original login account after sudo?
When the login chain sets loginuid correctly, auid usually retains the original login identity while euid reflects elevated privileges. An unset auid requires correlation with authentication and session records.
Does auditd preserve the full file contents before and after a change?
The rules in this article record operations, paths, processes and identities, not complete content differences. Restoring old content requires separate version history or backups.