Situatie
You want to track when someone or something opens a file (for debugging, auditing, or paranoia), but you don’t want to install or configure a full kernel-level auditing system like auditd.
Solutie
Solution Overview:
Use inotifywait in combination with a named pipe and a loop to passively log access to a file or directory in real-time, no root required.
Steps:
-
Install
inotify-tools:
-
Create a named pipe:
-
Set up the monitor (can be wrapped in a script):
-
Read and log entries with timestamps:
You can even redirect this into logger to send it to syslog:
Use Case Examples:
-
Track who or what is opening SSH config files or credential files
-
Debug unexpected file accesses in crontabs or systemd jobs
-
Monitor changes on a shared NFS directory or USB mount.
Caveats:
-
This only logs the
openevent — not modifications -
Will miss extremely fast events unless handled with care.
Leave A Comment?