This is an old revision of the document!
Table of Contents
How to install and configure AIDE on Ubuntu
AIDE (Advanced Intrusion Detection Environment) is a host-based file integrity checker. It monitors your filesystem for unauthorized changes (such as tampering with binaries, configs, or permissions).
Step 1. Install AIDE
sudo apt update sudo apt install aide -y
This installs AIDE and creates a default configuration file at:
/etc/aide/aide.conf
Step 2. Initialize the AIDE database
AIDE uses a baseline database of file checksums, permissions, and other metadata.
Initialize it with:
sudo aideinit
This command:
Scans your system according to the rules in /etc/aide/aide.conf.
Creates a new database at:
/var/lib/aide/aide.db.new
Then rename it to make it the active baseline:
sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Tip: Run this step only when the system is in a known good state (no malware, correct configs).
Step 3. Run checks
You can now manually check for changes anytime:
sudo aide --check
If files have been added, removed, or modified, AIDE will print a detailed report.
Typical output:
AIDE found differences between database and filesystem!! Summary: Total number of entries: 12345 Added entries: 2 Removed entries: 0 Changed entries: 1
To view details, scroll through the terminal or redirect output to a file:
sudo aide --check | less
Step 4. Update the database after legitimate changes
When you intentionally change system files (for example, after an update), rebuild the database:
sudo aide --update sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
This updates your baseline so AIDE won’t keep alerting you about legitimate changes.
Step 5. Automate daily checks (optional but recommended)
To automate AIDE checks, add a cron job:
sudo nano /etc/cron.daily/aide
Paste this script:
#!/bin/bash /usr/bin/aide --check | mail -s "AIDE Integrity Check Report - $(hostname)" root
Then make it executable:
sudo chmod +x /etc/cron.daily/aide
You can configure email delivery by setting up a local mailer (e.g., postfix or ssmtp) or redirect the report to a log file.
Step 6. (Optional) Customize configuration
Edit /etc/aide/aide.conf to include or exclude directories.
Examples:
# Add custom directory /etc p+i+n+u+g+s+m+c+acl+selinux+xattrs+sha512 # Exclude temporary directories !/tmp !/var/tmp !/run
Then reinitialize the database after saving changes:
sudo aideinit sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Good practices
Keep the AIDE database secure — store a copy offline or on read-only media. If attackers can alter both your files and the AIDE database, they can hide their tracks. Run after updates — rebuild the database only after verifying legitimate updates. Integrate with monitoring — send reports to a centralized system (email, SIEM, or log server).
How to configure custom AIDE rules on Ubuntu
AIDE’s power comes from its configuration file, usually located at:
/etc/aide/aide.conf
This file defines:
Which files/directories to monitor
What attributes to check (permissions, owner, checksums, etc.)
Which paths to ignore
Below, I’ll show you how to:
1. Understand rule syntax
2. Define your own rules
3. Configure AIDE to monitor only what you need
4. Test your configuration safely
Step 1. Understand AIDE rule syntax
Each line in aide.conf has this general format:
<path or pattern> <rule or rule name>
Examples:
/etc NORMAL /usr/bin NORMAL !/tmp
A line starting with ! means “exclude this path”.
A rule like NORMAL refers to a rule definition (explained next).
You can also directly specify what to check, like p+i+n+u+g+s+m+c+sha512.
Step 2. Understand the rule components
Each letter corresponds to an attribute to check.
Here are the most useful ones:
| Code | Meaning | Example |
|---|---|---|
| p | Permissions | File mode changes |
| i | Inode number | Detect moved/replaced files |
| n | Number of links | Detect added hard links |
| u | User (owner) | Owner changed |
| g | Group | Group ownership changed |
| s | Size | File grew/shrank |
| m | Modification time | Changed content |
| c | Change time (inode metadata) | Metadata change |
| a | Access time | (Usually ignored; too frequent) |
| sha512 | Hash algorithm | Detects content tampering |
Example combined rule:
p+i+n+u+g+s+m+c+sha512
→ Checks almost everything important, using SHA-512 for content integrity.
Step 3. Define your custom rules
Open the configuration file:
sudo nano /etc/aide/aide.conf
Scroll to the bottom (after the default rules) and add your own:
# ===== Custom Rules ===== # Define a strong rule for system configuration files CUSTOM = p+i+n+u+g+s+m+c+sha512 # Directories to monitor /etc CUSTOM /usr/bin CUSTOM /usr/sbin CUSTOM /var/www CUSTOM # Exclude temporary and runtime directories !/tmp !/var/tmp !/run !/proc !/sys !/dev !/mnt !/media
Explanation:
/etc — monitors configuration files. /usr/bin and /usr/sbin — monitors system executables. /var/www — monitors your web server files (if applicable). The excluded directories change too often or contain temporary data.
Step 4. Initialize AIDE again
After editing the config, you must rebuild the database:
sudo aideinit sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Step 5. Test your configuration
Run a manual check:
sudo aide --check
Change something intentionally (for testing):
sudo touch /etc/testfile
Run the check again:
sudo aide --check
You should see output like:
AIDE found differences between database and filesystem!! Added entries: 1 /etc/testfile
Then remove the test file and update your database if all is well:
sudo rm /etc/testfile sudo aide --update sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
Step 6. (Optional) Automate your custom checks
If you want AIDE to run your custom configuration daily, ensure the cron job (from the previous setup) uses this command:
/usr/bin/aide --config /etc/aide/aide.conf --check
Pro tips
Use multiple rules for different sensitivity levels:
SYSTEM = p+i+n+u+g+s+m+c+sha512 LOGS = p+u+g+s
Then apply them selectively:
/etc SYSTEM /var/log LOGS
Protect your AIDE database:
Store a copy offline or on read-only media (/root/aide-backups or USB).
Example backup:
sudo cp /var/lib/aide/aide.db /root/aide-backups/aide.db.$(date +%F)
Combine with systemd service (optional):
You can create a systemd timer to run AIDE weekly instead of using cron.
Summary
| Step | Command | Description |
|---|---|---|
| 1 | $ sudo nano /etc/aide/aide.conf | Edit configuration |
| 2 | Add custom rules | Define CUSTOM = p+i+n+u+g+s+m+c+sha512 |
| 3 | Add directories & exclusions | /etc, /usr/bin, /var/www, etc. |
| 4 | $ sudo aideinit | Rebuild baseline |
| 5 | $ sudo aide –check | Verify changes |
| 6 | (Optional) Automate | Cron or systemd timer |