Real-World Scenario: When a Server Is Silently Backdoored
For system operators, this is the ultimate nightmare scenario: attackers exploit a web application vulnerability (such as arbitrary file upload or RCE), escalate privileges, and quietly plant a backdoor in a cronjob. Even worse, they might replace binaries like /bin/ls or /bin/ps with a rootkit to conceal malicious processes. Meanwhile, CPU usage hovers at 5%, RAM usage stays flat, and your monitoring dashboards remain completely green.
How do you catch the intruders? The answer is File Integrity Monitoring (FIM).
FIM takes a “fingerprint” of all system files while the OS is in a known-good, clean state: SHA-256 checksums, inodes, permissions, file sizes, and mtime. Everything is compiled into a baseline reference database. During subsequent scans, if someone inserts a single space into /etc/pam.d/sshd or modifies a line in /etc/shadow, an alert is triggered immediately.
AIDE (Advanced Intrusion Detection Environment) is the premier open-source alternative to Tripwire. Its biggest advantage is that AIDE does not run a continuous background daemon consuming system resources. At idle, it uses 0 MB of RAM; during scans, it consumes only about 30–60 MB for 2–3 minutes, making it ideal for everything from a 1GB RAM VPS to a multi-node bare-metal cluster.
To set up a hardened server, generating secure root and user passwords is vital from the start. You can use the password generator at toolcraft.app/en/tools/security/password-generator to generate random passwords 20–32 characters in length. Because this tool runs 100% in your browser, your data is never exposed across the network. Once generated, configure SSH keys and proceed with setting up AIDE.
Installing AIDE
The installation package is available in the official repositories of most Linux distributions.
On Ubuntu / Debian:
sudo apt update
sudo apt install aide aide-common -y
On RHEL / Rocky Linux / AlmaLinux:
sudo dnf install aide -y
Once installed, verify the version by running:
aide -v
Configuring AIDE: Accurate Monitoring Without False Alarm Spam
The greatest challenge in deploying FIM is managing false positives. If you accidentally monitor directories like /var/log or /tmp, midnight log rotations (via logrotate) will flood your inbox with hundreds of junk alert emails.
Configuration file locations:
- Ubuntu / Debian:
/etc/aide/aide.confor split across the/etc/aide/aide.conf.d/directory - RHEL / Rocky / CentOS:
/etc/aide.conf
1. Defining Rule Sets
AIDE uses flags to represent individual file metadata attributes:
- p: Access permissions
- i: Inode number
- n: Number of hard links
- u / g: Owning user and group
- s: File size
- m / c: Modification time (mtime) and metadata change time (ctime)
- sha256: SHA-256 file content checksum
We can group these into two practical profiles:
# Inspect executable binaries and system libraries thoroughly
BIN_RULES = p+i+n+u+g+s+m+c+sha256
# Inspect configuration files: allow size changes but strictly enforce mtime and hash checks
CONF_RULES = p+u+g+m+c+sha256
2. Applying Rules to the Directory Tree
Add critical directories to the bottom of the configuration file. Use an exclamation mark (!) prefix to exclude dynamic data paths:
# 1. Executable directories requiring strict protection
/bin BIN_RULES
/sbin BIN_RULES
/usr/bin BIN_RULES
/usr/sbin BIN_RULES
/boot BIN_RULES
# 2. Sensitive configuration files
/etc CONF_RULES
# 3. EXCLUDE directories with frequent dynamic changes
!/var/log/.*
!/var/spool/.*
!/var/tmp/.*
!/tmp/.*
!/etc/mtab
!/etc/aide/.*\.db.*$
Tip for Ubuntu: If you edit configurations in /etc/aide/aide.conf.d/, run sudo update-aide.conf to compile them into the consolidated configuration file before initializing the database.
Initializing the Baseline Database
After finalizing your rules, generate a clean baseline snapshot of the system.
On Ubuntu/Debian, run:
sudo aideinit
On RHEL/Rocky Linux, run:
sudo aide --init
On an SSD scanning around 50,000 files, this process takes about 1–3 minutes. It generates a /var/lib/aide/aide.db.new file (or with a .gz extension). AIDE will not use this file immediately; you must activate it as the official baseline database:
sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db
# If your distro uses gz compression:
# sudo cp /var/lib/aide/aide.db.new.gz /var/lib/aide/aide.db.gz
Testing Intrusion Detection & Automation
Let’s run a test to see whether AIDE catches unauthorized tampering.
1. Simulating an Attack
Simulate an intrusion by injecting an entry into your hosts file and creating a backdoor script:
echo "# Fake entry" | sudo tee -a /etc/hosts
sudo touch /usr/local/bin/backdoor.sh
Run the integrity check:
sudo aide --check
AIDE will output the detailed comparison report to your terminal:
AIDE found differences between database and current filesystem!!
Summary:
Total number of entries: 48210
Added entries: 1
Removed entries: 0
Changed entries: 1
---------------------------------------------------
Added entries:
---------------------------------------------------
/usr/local/bin/backdoor.sh
---------------------------------------------------
Changed entries:
---------------------------------------------------
/etc/hosts: mtime, ctime, sha256
AIDE successfully catches the newly created suspicious file and identifies the modified SHA-256 checksum on /etc/hosts.
2. Sync Workflow After OS Updates (apt/dnf upgrade)
Every time you run apt upgrade, hundreds of system binaries have their checksums legitimately updated. To prevent AIDE from triggering false alarms, resynchronize the database immediately after maintenance:
sudo aide --update
sudo cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db
3. Automating Periodic Scans with Cron
Open root’s crontab using sudo crontab -e and schedule a daily scan at 3:00 AM:
0 3 * * * /usr/bin/aide --check 2>&1 | /usr/bin/mail -s "[AIDE Alert] Integrity Report on $(hostname)" [email protected]
Battle-Tested Advice: Preventing Attackers from Tampering with the AIDE Database
If an attacker escalates to root, their first move is often running aide --update to legitimize their backdoor. To mitigate this risk, consider two defense strategies:
- Lock the database file: Run
sudo chattr +i /var/lib/aide/aide.dbto set the immutable flag. Even the root user cannot modify or delete this file without first removing the attribute viachattr -i. - Isolated storage (Best practice): After each initialization or update, use rsync to transfer the
aide.dbfile to a dedicated, read-only storage server. When performing checks, pull the clean reference database back down for verification.
