auditd and AIDE: who touched what
This lesson is open to everyone. The other lessons open with a package: sign in or sign up, then choose a package.
Key points
- auditd runs by default on RHEL; its log is
/var/log/audit/audit.log(SELinux AVC messages are here too). - A file watch rule:
auditctl -w /etc/passwd -p wa -k identity; permanent rules go in/etc/audit/rules.d/*.rules+augenrules --load. - Search:
ausearch -k identity -i, report:aureport --summary; auid shows the real logged-in user even after sudo. - AIDE is a database of file fingerprints:
aide --init→ put the database in place →aide --checkshows what changed. - After an expected change (e.g.
dnf update), refresh the database withaide --update; keep a copy of the database off the server.
Two tools, two questions
| Tool | Question | How it works |
|---|---|---|
| auditd | Who touched it, when, with which command? | Records kernel events as they happen |
| AIDE | What changed? | Compares file hashes and attributes with a database |
auditd catches an event the moment it happens; AIDE checks afterwards. One answers "who", the other "what" — together they give the full picture.
auditd
On RHEL 9 auditd is installed and running:
[ali@srv-web01 ~]$ systemctl is-active auditd active [ali@srv-web01 ~]$ sudo auditctl -s enabled 1 failure 1 pid 812 backlog_limit 8192 lost 0 backlog 0 [ali@srv-web01 ~]$ sudo auditctl -l No rules
No rules means there are no file watch rules, but logins, sudo and SELinux events are still recorded.
Adding a rule
[ali@srv-web01 ~]$ sudo auditctl -w /etc/passwd -p wa -k identity [ali@srv-web01 ~]$ sudo auditctl -w /etc/httpd/conf.d/ -p wa -k httpd-conf [ali@srv-web01 ~]$ sudo auditctl -l -w /etc/passwd -p wa -k identity -w /etc/httpd/conf.d -p wa -k httpd-conf
| Part | Meaning |
|---|---|
-w path | Watch this file or folder |
-p wa | Permissions: w write, a attribute change, r read, x execute |
-k key | A name for searching |
A rule added with auditctl is lost on reboot. To make it permanent, write it to a file:
[ali@srv-web01 ~]$ sudo tee /etc/audit/rules.d/itnuvo.rules <<'EOF' -w /etc/passwd -p wa -k identity -w /etc/shadow -p wa -k identity -w /etc/sudoers -p wa -k sudoers -w /etc/sudoers.d/ -p wa -k sudoers -w /etc/httpd/conf.d/ -p wa -k httpd-conf EOF [ali@srv-web01 ~]$ sudo augenrules --load [ali@srv-web01 ~]$ sudo auditctl -l
auditd cannot be restarted with systemctl restart (its unit file forbids it) — use augenrules --load for rules and, if needed, sudo service auditd restart.
Searching
Let someone touch /etc/passwd:
[ali@srv-web01 ~]$ sudo useradd testuser [ali@srv-web01 ~]$ sudo ausearch -k identity -i --start today ---- type=PROCTITLE msg=audit(12/01/2026 14:22:05.311:1842) : proctitle=useradd testuser type=PATH msg=audit(12/01/2026 14:22:05.311:1842) : item=1 name=/etc/passwd ... type=SYSCALL msg=audit(12/01/2026 14:22:05.311:1842) : arch=x86_64 syscall=openat success=yes ... auid=ali uid=root ... comm=useradd exe=/usr/sbin/useradd key=identity
| Field | Meaning |
|---|---|
auid=ali | Who logged in (audit user id) — does not change after sudo |
uid=root | Which user the command ran as |
comm, exe | Which program |
success=yes | The operation succeeded |
key=identity | Which rule caught it |
auid is the most important field: even if everyone becomes root with sudo, you know who did it.
[ali@srv-web01 ~]$ sudo aureport --summary [ali@srv-web01 ~]$ sudo aureport -au --start today [ali@srv-web01 ~]$ sudo aureport -k --start today [ali@srv-web01 ~]$ sudo ausearch -m USER_LOGIN --success no -i --start today
The last one shows today's failed logins. SELinux denials are here too: ausearch -m AVC -ts recent.
AIDE
[ali@srv-web01 ~]$ sudo dnf install -y aide [ali@srv-web01 ~]$ sudo aide --init Start timestamp: 2026-12-01 14:30:12 +0400 (AIDE 0.16) AIDE initialized database at /var/lib/aide/aide.db.new.gz ... [ali@srv-web01 ~]$ sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
--init creates a new database, but AIDE reads aide.db.gz when checking — so we rename it. What is watched is set in /etc/aide.conf (by default /etc, /boot, /usr/bin, /usr/sbin and more).
Checking
[ali@srv-web01 ~]$ sudo sed -i 's/^#Port 22/Port 22/' /etc/ssh/sshd_config [ali@srv-web01 ~]$ sudo aide --check AIDE found differences between database and filesystem!! Summary: Total number of entries: 45210 Added entries: 0 Removed entries: 0 Changed entries: 1 --------------------------------------------------- Changed entries: --------------------------------------------------- f ... .C... : /etc/ssh/sshd_config ...
C means the content hash changed. If the change was expected (you made it, or there was a dnf update), refresh the database:
[ali@srv-web01 ~]$ sudo aide --update [ali@srv-web01 ~]$ sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
Automating and protecting the database
[ali@srv-web01 ~]$ echo '30 4 * * * root /usr/sbin/aide --check' | sudo tee /etc/cron.d/aideIf an attacker has become root, they can change the AIDE database too. So after each refresh keep a copy of the database off the server (on another server, on read-only media), and when in doubt run the check against that copy.
Lab: set up monitoring
On your own VM:
- Write rules for
/etc/passwd,/etc/shadowand/etc/sudoersin/etc/audit/rules.d/itnuvo.rulesand runaugenrules --load. - Run
sudo useradd labtestand see withausearch -k identity -ithatauidis your name. - Look at
aureport --summaryand the report of failed logins. - Install AIDE, create the database and put it in place.
- Add a line to
/etc/motd;aide --checkshould show it; then refresh the database.
[ali@srv-web01 ~]$ sudo auditctl -l [ali@srv-web01 ~]$ sudo ausearch -k identity -i --start today [ali@srv-web01 ~]$ sudo aide --check
Check: in the ausearch output auid= is your user, and aide --check shows /etc/motd as changed.
Check yourself
5 questions · answers are shown instantly · 3 correct answers complete the lesson
1Where is the auditd log kept?
2In the rule auditctl -w /etc/passwd -p wa -k identity, what does -p wa mean?
3Which field in the audit log shows a user who became root with sudo?
4What does AIDE do?
5After dnf update AIDE shows many changes. The right step?
Comments
Sign in to comment.