Linux Labs

Server security / Stage 9 of 10

Who changed the file: auditd

Not running Starting usually ~20 s
Leave the lesson

Step 2 of 6 · on a machine · 8 min

Watching a file

Ordinary permissions and a service's log do not say who wrote to a file. auditd answers that question — the kernel audit service: by a rule it records every access to a file along with who made it.

In the image auditd is off — you start it first:

bash
sudo systemctl enable --now auditd
Note

With auditd running, the AppArmor denials from the previous lesson go to its log, /var/log/audit/audit.log: sudo ausearch -m AVC -i gets them, and journalctl -k has no new lines (in the Wiki).

An audit rule is set with auditctl:

bash
sudo auditctl -w /etc/hosts -p wa -k hosts

-w is the path to watch; -p wa is which access to record (w for write, a for attribute change, also r for read and x for execute); -k hosts is a key by which you later search for events. sudo auditctl -l shows the installed rules.

Events for a key are fetched with ausearch:

bash
sudo ausearch -k hosts -i        # -i turns numbers into names
Exercise · do it

Set a watch on /etc/hosts

Start the auditd service and set a watch on /etc/hosts with the key hosts for writes and attribute changes. Within a few seconds an event under that key must appear in the audit — the service edits the file again right then.

Sign in and start The machine is available after signing in

Goals · 0 of 2

  • Start the auditd service not done yet
  • Set a watch on /etc/hosts with the key hosts not done yet

Step goals

0 of 2
  • Start the auditd service — not done yet
  • Set a watch on /etc/hosts with the key hosts — not done yet
Ubuntu 24.04

Step goals

0 of 2
  • Start the auditd service — not done yet
  • Set a watch on /etc/hosts with the key hosts — not done yet
Loading…