It is 2:14 AM, and a monitoring alert just woke you up. Outbound traffic from your web server spiked, CPU sits at 90%, and top shows nothing unusual. Maybe an attacker swapped a system binary, or dropped a PHP webshell into /var/www. Without a snapshot of what your filesystem looked like yesterday, you are stuck guessing which files changed.
AIDE (Advanced Intrusion Detection Environment) solves that problem. It records a cryptographic baseline of your critical files and flags any unauthorized change—from modified permissions to altered file hashes. Here is how to deploy it in minutes and tune it for real incident response.
Quick Start: Get AIDE Running in 5 Minutes
Getting File Integrity Monitoring (FIM) active takes just three steps. Both Debian-based and RHEL-based distributions ship AIDE in their default repositories.
1. Install AIDE
Debian and Ubuntu systems use apt:
sudo apt update && sudo apt install -y aide aide-common
RHEL, AlmaLinux, and Rocky Linux use dnf:
sudo dnf install -y aide
2. Initialize the Baseline Database
Before running checks, AIDE needs a clean reference database. Build this right after provisioning a fresh server—not after you suspect a compromise.
Ubuntu and Debian include a wrapper script that builds the config and initializes the database:
sudo aideinit
sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db
On RHEL and AlmaLinux, run the binary directly and rename the compressed output:
sudo aide --init
sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
3. Run Your First Integrity Check
With the baseline in place, run a manual scan to verify everything matches:
# Ubuntu / Debian
sudo aide.wrapper --check
# RHEL / AlmaLinux
sudo aide --check
A clean system exits with status 0 and prints zero diffs. Any added script or modified binary triggers a non-zero exit code and a detailed report.
Under the Hood: How AIDE Catches Tampered Files
AIDE works like a strict notary for your filesystem. During initialization, it walks every path defined in /etc/aide/aide.conf (or /etc/aide.conf on RHEL) and stores file metadata plus cryptographic hashes in a local database. For a typical 50,000-file web server, that database takes roughly 15 MB on disk.
What Attributes AIDE Tracks
Rules in AIDE combine single-letter attribute flags and hash names. These are the ones you will use most often:
p: File permissionsi: Inode number (catches files replaced via atomic rename)n: Hard link countuandg: User and group ownerships: Exact file size (use uppercaseSfor append-only logs)mandc: Modification time (mtime) and status change time (ctime)sha256/sha512: Cryptographic content hashes
Most distros group these flags into presets like FIPSR or NORMAL. Writing your own rule for system binaries is just as simple:
BIN_RULE = p+i+n+u+g+s+m+c+sha256
Reading an AIDE Alert During a 2 AM Triage
Suppose an attacker modifies /usr/local/bin/backup.sh and drops a webshell at /var/www/html/cache.php. AIDE prints a summary first, followed by the exact attribute diffs:
AIDE found differences between database and filesystem!!
Summary:
Total number of entries: 48210
Added entries: 1
Removed entries: 0
Changed entries: 1
---------------------------------------------------
Added entries:
---------------------------------------------------
f++++++++++++++++: /var/www/html/cache.php
---------------------------------------------------
Changed entries:
---------------------------------------------------
f ... : /usr/local/bin/backup.sh
---------------------------------------------------
Detailed information about changes:
---------------------------------------------------
File: /usr/local/bin/backup.sh
Size : 1024 | 1482
Mtime : 2026-11-10 09:12:04 +0000 | 2026-12-05 02:08:41 +0000
SHA256 : n4bQgYhMfWWaL+qgxVrQFaO/TxsrC4Is0V1sFbDwCgg= | SyJ3d9TdcWFs+ISPSkHCA==
Compare that to grepping through thousands of files half-asleep. You immediately get two file paths and an exact timestamp (02:08:41) to cross-reference against SSH and Nginx logs.
Tuning Rules, Automation, and Scan Speed
Default AIDE configs often hash volatile cache directories using four or five algorithms at once (MD5, SHA1, SHA256, SHA512, and RMD160). That wastes CPU cycles and floods your inbox with false positives.
Create a Focused Custom Policy
Drop a custom policy into /etc/aide/aide.conf.d/99_custom_fim.conf (or /etc/aide.conf on RHEL). Stick to sha256 for critical directories and exclude noisy paths with !:
# Custom high-speed integrity rule
CRITICAL = p+i+n+u+g+s+m+c+sha256
LOG_GROW = p+u+g+i+n+S
# Watch binaries, configs, and web roots
/bin CRITICAL
/sbin CRITICAL
/usr/bin CRITICAL
/usr/sbin CRITICAL
/etc CRITICAL
/var/www/html CRITICAL
# Logs should only grow, not shrink or change ownership
/var/log/auth.log LOG_GROW
# Exclude volatile and virtual filesystems
!/proc
!/sys
!/dev
!/tmp
!/run
!/var/cache
!/var/lib/docker/overlay2
On a 2-vCPU, 4 GB RAM Ubuntu 22.04 server with ~48,000 tracked files, default multi-hash rules took 18 minutes and saturated disk I/O. After adding the exclusions above and switching to sha256 alone, the same check finished in 95 seconds.
Automate Checks with a Systemd Timer
Manual scans only catch what you remember to check. Schedule AIDE with systemd so it runs every six hours and logs straight to journald.
Save the service unit at /etc/systemd/system/aide-check.service (use /usr/sbin/aide.wrapper on Debian/Ubuntu instead of /usr/bin/aide):
[Unit]
Description=AIDE File Integrity Check
[Service]
Type=oneshot
ExecStart=/usr/bin/aide --check
SuccessExitStatus=0 1 2 3 4 5 6 7
Notice SuccessExitStatus lists 0 through 7. AIDE uses bitmask exit codes: 1 for added files, 2 for removed, and 4 for changed (so 7 means all three happened). Codes 14 and above indicate actual runtime errors.
Next, create /etc/systemd/system/aide-check.timer:
[Unit]
Description=Run AIDE check every 6 hours
[Timer]
OnCalendar=*-*-* 00/6:00:00
Persistent=true
[Install]
WantedBy=timers.target
Reload systemd and enable the timer:
sudo systemctl daemon-reload
sudo systemctl enable --now aide-check.timer
Want Slack or email alerts? Wrap the check in a short bash script that posts to a webhook whenever the exit code is between 1 and 7.
Updating the Baseline After Planned Maintenance
Running apt upgrade or deploying new code will naturally trigger AIDE diffs. Refresh the database right after verifying your changes:
# Ubuntu / Debian
sudo aide.wrapper --update
sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
# RHEL / AlmaLinux
sudo aide --update
sudo mv /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
Practical Tips from 2 AM Incident Response
- Never trust a local-only database: An attacker with root access can run
aide --updateand bake their rootkit into your baseline. Ship a copy ofaide.dbandaide.confto an S3 bucket with Object Lock or a read-only NFS share. - Verify the AIDE binary itself: Kernel or userland rootkits can trojanize
/usr/bin/aideto hide specific files. Keep the binary’s SHA-256 hash offline, or boot from a clean rescue ISO during forensics. - Clear diffs after every patch window: Ignoring 300 noisy diffs from Tuesday’s kernel update guarantees you will miss the single malicious binary added on Friday.
- Test exclusions with
--limit: Tuning rules for/var/www/htmldoes not require a full-disk scan. Runsudo aide --check --limit ^/var/www/htmlto verify your regex in under five seconds.
