Course contentsShow
← Security
Lesson 1493 of 3,05230. Operating System Security - MonitoringFree lesson

File and Directory Watch Rules

Creating audit rules to monitor file access, modifications, attribute changes, and tracking suspicious file system activity.

File and Directory Watch Rules

What you'll learn: How to create audit rules that monitor file access, modifications, and suspicious activity on critical system files and directories.

Why Watch Files?

Think of file watch rules as security cameras for your filesystem. Just as a camera records who enters a room and what they do, audit watches track who accesses files, what changes they make, and when suspicious activity occurs. This creates an immutable record for forensic analysis and compliance.

Core Concepts

File and directory watches use the auditctl command to tell the Linux auditing framework which files to monitor and what events to capture. You specify:

  • Target path — the file or directory to watch
  • Permissions to monitor — read (r), write (w), execute (x), attribute changes (a)
  • Key/tag — a label to help filter and search logs later

Basic Watch Syntax

To watch a critical file like /etc/passwd:

auditctl -w /etc/passwd -p wa -k passwd_changes

This monitors write and attribute changes, tagging events with passwd_changes.

For directory monitoring with recursion:

auditctl -w /etc/ssh/ -p wa -k ssh_config_changes

Common Monitoring Scenarios

  • Configuration files — watch /etc/ subdirectories for unauthorized changes
  • Binaries — monitor /usr/bin/ and /usr/sbin/ for trojan insertion
  • Sensitive data — track access to /var/log/ or /home/ directories
  • Temporary files — watch /tmp/ for malware staging activity

Review events later using ausearch -k passwd_changes to find all tagged events.

Key Takeaway: File and directory watch rules transform your filesystem into an auditable space where every access, modification, and attribute change leaves a searchable trail, essential for detecting intrusions and meeting compliance requirements.