Security and hardening · Intermediate · 15 min
Detect changed system files on a server with AIDE
By Padding · Updated 18 Nov 2026
Ubuntu 26.04.1 LTS · AIDE 0.19.2
You will have AIDE 0.19 keeping a checksum baseline of an Ubuntu 26.04 server, reporting a planted change, ignoring noisy directories, accepting planned upgrades and running every day from its packaged timer.
On this page
If someone gets root on a server, the first thing they usually do is make sure they can come back: a new cron job, an extra SSH key, a patched binary. Logs can be cleaned. Files that changed on disk are harder to hide, if you recorded what they looked like before.
AIDE (Advanced Intrusion Detection Environment) does that recording. It walks the file system, stores each file's permissions, owner, size, timestamps and checksums in a database, and later compares the disk against that database. It reports what was added, removed or changed. It does not block anything, and it cannot tell a deploy from an attack. You decide which is which.
In this tutorial you will install AIDE from the Ubuntu archive, build a baseline, plant changes and catch them, read the report line by line, tune out a noisy cache directory, accept a planned package install into a new baseline, and hand the job to the daily timer that ships with the package.
Step 1 · Install AIDE
Ubuntu 26.04 ships AIDE 0.19.2 in two packages: aide, the program, and aide-common, which holds Debian's tuned configuration, the aideinit helper and the daily timer. Installing aide pulls in both.
sudo apt-get update
sudo apt-get install -y aideThe main configuration is /etc/aide/aide.conf. It sets the database paths and groups of attributes, then includes every file in /etc/aide/aide.conf.d/ whose name has only letters, digits, _ and -. A file named 90_local.conf is silently skipped because of the dot. The last included rule, / 0 Full, watches everything that earlier rules did not exclude.
Check it worked
aide --version 2>&1 | head -n 1
sudo aide --config /etc/aide/aide.conf --config-check && echo "config OK"The first line names the version, something like Aide 0.19.2. The second prints config OK. Any parse error prints the file and line instead.
Step 2 · Create a small app to watch
To see AIDE react to something you control, make a small fake app in /opt/aide-demo: two scripts in bin/ that should never change outside a deploy, and a cache/ directory that it rewrites all the time. Also make a working folder in your home directory for the reports.
sudo install -d -m 755 /opt/aide-demo/bin /opt/aide-demo/cache
sudo tee /opt/aide-demo/bin/report.sh > /dev/null <<'EOF'
#!/bin/sh
echo "daily report"
EOF
sudo tee /opt/aide-demo/bin/cleanup.sh > /dev/null <<'EOF'
#!/bin/sh
echo "old cleanup job"
EOF
sudo chmod 755 /opt/aide-demo/bin/report.sh /opt/aide-demo/bin/cleanup.sh
mkdir -p ~/aide-demoCheck it worked
ls -l /opt/aide-demo/bin
wc -c /opt/aide-demo/bin/report.shYou see cleanup.sh and report.sh with -rwxr-xr-x permissions, owned by root, and wc -c reports that report.sh is 30 bytes.
Step 3 · Build the baseline and keep a copy off the server
aideinit runs aide --init with the packaged configuration, writes the new database to /var/lib/aide/aide.db.new, and with -f copies it to /var/lib/aide/aide.db, the file every later check compares against. -y answers yes to overwriting an older database. The first run reads every watched file, so it takes from under a minute on a small server to much longer on one with large data directories.
Build the baseline on a server you trust. A baseline taken after a break-in faithfully records the intruder's files as normal.
sudo aideinit -y -fAn attacker with root can also rewrite /var/lib/aide/aide.db so that their changes look normal. Keep a copy somewhere they cannot reach. The database is root-only, so copy it into your home folder as a private file first:
(umask 077; sudo cat /var/lib/aide/aide.db > ~/aide-demo/baseline.db)
ls -lh ~/aide-demo/baseline.db
sha256sum ~/aide-demo/baseline.dbThe database is gzip-compressed (gzip_dbout=yes in the config). Check the size ls -lh prints before you pull it over a metered or prepaid mobile connection; on a minimal server it is small.
Then, on your laptop, fetch it and record the checksum. Replace you@your-server with your own login:
# On your laptop
scp you@your-server:aide-demo/baseline.db ./aide-baseline-$(date +%F).db
shasum -a 256 aide-baseline-*.dbThe checksum on the laptop must match the one the server printed. Remove the transit copy from the server once you have it:
rm ~/aide-demo/baseline.dbLater, if you doubt the server's database, compare sudo sha256sum /var/lib/aide/aide.db with the checksum you kept. A mismatch you did not cause means the baseline itself was touched.
Check it worked
sudo ls -l /var/lib/aide/You see aide.db and aide.db.new, both owned by root and readable only by root.
Step 4 · Plant changes and run a check
Now make the kind of changes AIDE exists to catch: two changes that matter and some cache noise. All of them are harmless: an extra line in report.sh, a cron file that holds only a comment, and a few cache files.
echo 'echo "copied to backup"' | sudo tee -a /opt/aide-demo/bin/report.sh > /dev/null
echo '# aide demo: a comment only, no schedule' | sudo tee /etc/cron.d/aide-demo > /dev/null
for i in 1 2 3; do date | sudo tee /opt/aide-demo/cache/page-$i.html > /dev/null; doneRun a check and save the report. AIDE's exit code tells you what kind of differences it found, so keep that too:
rc=0
sudo aide --config /etc/aide/aide.conf --check > ~/aide-demo/check-1.txt || rc=$?
echo "aide exit code: $rc"The exit code is a sum: 1 if files were added, 2 if files were removed, 4 if files changed. Here you added files and changed one, so expect aide exit code: 5. 0 means no differences. A code of 14 or higher is an error, such as a missing database or a bad config line.
Check it worked
head -n 12 ~/aide-demo/check-1.txtThe report starts with a line like AIDE found differences between database and filesystem!! and a summary with counts of total, added, removed and changed entries.
Step 5 · Read the report
Open the whole report:
less ~/aide-demo/check-1.txtAfter the summary come three lists, Added entries, Removed entries and Changed entries, then a section of detailed information for each changed file. Pull out the lines for the two changes that matter and the cache noise:
grep -E 'cron\.d/aide-demo|aide-demo/bin|aide-demo/cache' ~/aide-demo/check-1.txtEach entry line starts with a short summary string, something like this:
f++++++++++++++++++: /etc/cron.d/aide-demo
f++++++++++++++++++: /opt/aide-demo/cache/page-1.html
d =.... mc.. .. . : /opt/aide-demo/cache
f >.... mc..H.. . : /opt/aide-demo/bin/report.shThe exact spacing depends on which attributes the matching rule checks. Read it column by column:
- The first character is the file type:
ffile,ddirectory,lsymbolic link,!the type itself changed. - A new file shows
+in every column, and a removed file shows-in every column. - In the size column,
>means the file grew,<it shrank and=it stayed the same size. - A letter means that attribute changed:
bblock count,ppermissions,uowner,ggroup,mmodification time,cchange time,iinode,nlink count,Hchecksums. A.means checked and unchanged. A space means not checked.
So report.sh grew and its content hash changed, while its owner and permissions did not. The extra line still fits in the same disk block, so the block count column stays .. That pattern is what an appended line looks like. The detailed section below the lists shows old and new values side by side, with lines something like Size : 30 | 54 (check the new size with wc -c /opt/aide-demo/bin/report.sh) and the old and new SHA-256 and other hashes.
How to triage a report:
- New files in
/etc/cron.d,/etc/systemd/system,~/.ssh/authorized_keysor/usr/local/binthat nobody planned are the most urgent. Treat them as an incident until you can explain them, and see/tutorials/collect-evidence-from-a-linux-server-after-a-suspected-breach. - A changed checksum on a binary in
/usr/binor/usr/sbinwith no package upgrade in/var/log/dpkg.logat that time is serious. - Changes you can match to a deploy, a package upgrade or your own edit are expected. You accept them in a later step.
- The cache files are noise. They change every time the app runs and say nothing about security.
Check it worked
You can say, for each of the four lines above, whether it is a planted change, a change a deploy would explain, or noise. If the cache lines were not there, your report would be short enough to read every day, which is the aim of the next step.
Step 6 · Tune out the noise
A report with hundreds of entries every morning gets skimmed, then ignored. Debian's packaged rules in /etc/aide/aide.conf.d/ already handle the logs, caches and spool files of common packages. Your own apps are where the noise comes from, so add a local rule file for them.
There are two kinds of exclusion. !/path drops paths that match the regular expression but still looks inside directories. -/path, new in AIDE 0.19, drops the matching entry and does not look inside it at all, which suits a whole cache directory. Paths are regular expressions matched from the start, so end them with $ to avoid catching /opt/aide-demo/cache-old as well.
Exclude the app cache and your report folder. The file name has no dot, so the include rule picks it up:
printf '%s\n' '# Local rules for the aide-demo app' '-/opt/aide-demo/cache$' "-$HOME/aide-demo\$" | sudo tee /etc/aide/aide.conf.d/90_local_aide-demo
sudo aide --config /etc/aide/aide.conf --config-check && echo "config OK"Ask AIDE how it now treats two paths, without running a full check. --path-check exits 0 if a path would be recorded and 1 if it would not:
sudo aide --config /etc/aide/aide.conf --path-check=d:/opt/aide-demo/cache || echo "cache: not watched (exit $?)"
sudo aide --config /etc/aide/aide.conf --path-check=f:/opt/aide-demo/bin/report.sh && echo "report.sh: watched"Exclude as narrowly as you can. Never exclude whole trees such as /etc, /usr, /home or /var/www to quiet a report: those are where an intruder's changes go. For a log file that only grows, give it a log rule instead of excluding it; aide.conf defines groups for this, such as ActLog for a live log.
Check it worked
Run the check again against the same baseline:
rc=0
sudo aide --config /etc/aide/aide.conf --check > ~/aide-demo/check-2.txt || rc=$?
echo "aide exit code: $rc"
grep -c '/opt/aide-demo/cache/' ~/aide-demo/check-2.txt || echo "no cache files listed"
grep -E '^d-+: ' ~/aide-demo/check-2.txtThe cache files are gone from the report: grep -c prints a count of 0 and exits with an error, which triggers the echo. The exit code is now 7, because the baseline still holds the two directories you just excluded. They are listed once under removed entries, as d------------------: /opt/aide-demo/cache and the same for your report folder, and drop out when you accept the next baseline. The cron file and report.sh are still listed, because nothing has accepted them yet.
Step 7 · Accept planned changes into a new baseline
Decide on each remaining entry. Say the cron file is one nobody can explain: remove it. Say the change to report.sh was a deploy you made: keep it, and say that deploy also retired cleanup.sh, so remove that too. Then do a planned upgrade, which here is installing one small package, so that the new baseline includes it:
sudo rm /etc/cron.d/aide-demo
sudo rm /opt/aide-demo/bin/cleanup.sh
sudo apt-get install -y treeaide --update runs a check and writes a fresh database to /var/lib/aide/aide.db.new in the same pass. It leaves the current baseline alone, so read the report before you accept it:
rc=0
sudo aide --config /etc/aide/aide.conf --update > ~/aide-demo/update-1.txt || rc=$?
echo "aide exit code: $rc"
grep -E '/usr/bin/tree|aide-demo/bin' ~/aide-demo/update-1.txtYou see /usr/bin/tree under added entries, cleanup.sh and the two excluded directories under removed entries, and report.sh under changed entries, with an exit code of 7 (1 + 2 + 4). The cron file has dropped out of the report: the baseline was built before you planted it, so once it is deleted the disk matches the baseline again. At most the /etc/cron.d directory itself shows as changed, because its timestamps moved.
If anything else is listed that you cannot explain, stop here and investigate before you go on.
When every entry is explained, make the new database the baseline:
sudo cp -p /var/lib/aide/aide.db.new /var/lib/aide/aide.dbThe baseline has changed, so copy it to your laptop again as you did when you built it, and record the new checksum. Do this after every accepted update, or the copy you keep stops being useful.
Check it worked
rc=0
sudo aide --config /etc/aide/aide.conf --check > ~/aide-demo/check-3.txt || rc=$?
echo "aide exit code: $rc"The exit code is 0 and the report says AIDE found no differences between the database and the file system.
Step 8 · Run it every day with the packaged timer
aide-common ships dailyaidecheck.timer, which starts dailyaidecheck.service once a day at 01:50 plus a random delay of up to two hours, and catches up after a reboot if a run was missed. See whether it is active, and enable it if not:
systemctl list-timers dailyaidecheck.timer
sudo systemctl enable --now dailyaidecheck.timerThe daily job reads its settings from /etc/default/aide. Open it with sudoedit /etc/default/aide and look at these:
COMMAND=updatemakes each run write a freshaide.db.newas well as the report. Keep it.COPYNEWDB=nomeans the new database never replaces the baseline on its own. Keep it, so a person reviews every change, as you did in the previous step.MAILTOsets who gets the report and defaults toroot. Set it to a mailbox someone reads, such asMAILTO=ops@example.com(replace this).
Mail needs s-nail or mail and a working mail relay on the server. Without them, the job warns that it cannot send mail and still writes the full report to /var/log/aide/aide.log. If your team reads alerts somewhere other than email, ship that log file to the place they do watch.
Run the job once now instead of waiting for the night:
sudo systemctl start dailyaidecheck.service
sudo tail -n 30 /var/log/aide/aide.log
journalctl -u dailyaidecheck.service -n 20 --no-pagerCheck it worked
systemctl list-timers dailyaidecheck.timer shows a next run time within the coming day, and /var/log/aide/aide.log holds a report with a timestamp from your manual run. After each package upgrade or deploy, the next daily report lists the files it touched; review them and accept them with the copy command from the previous step.
Step 9 · Remove the demo
Remove the demo app, its rule file, the reports and the practice package, then accept their removal into the baseline so tomorrow's report is clean. This deletes /opt/aide-demo and ~/aide-demo; check that neither holds anything of yours first.
sudo rm -rf /opt/aide-demo
sudo rm /etc/aide/aide.conf.d/90_local_aide-demo
rm -rf ~/aide-demo
sudo apt-get remove -y tree
sudo aide --config /etc/aide/aide.conf --update > /dev/null || echo "changes recorded (exit $?)"
sudo cp -p /var/lib/aide/aide.db.new /var/lib/aide/aide.dbCopy the new baseline to your laptop once more and delete the older demo copies there.
Check it worked
rc=0
sudo aide --config /etc/aide/aide.conf --check > /dev/null || rc=$?
echo "aide exit code: $rc"The exit code is 0. AIDE stays installed with the packaged rules and the daily timer.
Next steps
- Measure the rest of the server's hardening and track it over time:
/tutorials/audit-a-server-with-lynis. - Reduce what a compromised service could change in the first place:
/tutorials/sandbox-a-systemd-service-with-security-options. - Pair file changes with login evidence when a report surprises you:
/tutorials/detect-suspicious-logins-in-the-auth-log. - If a change has no innocent explanation:
/tutorials/collect-evidence-from-a-linux-server-after-a-suspected-breach.
Related tutorials
- Write custom Fail2ban jails and filters for your own appsYou will have Fail2ban 1.1 banning repeated failed sign-ins to your own app and to an nginx basic-auth area, with filters you tested against sample logs, your own addresses allow-listed, and longer bans for repeat offenders.
- Validate file uploads before you store or serve themYou will take a FastAPI image upload route that trusts everything the browser sends, prove its flaws with pytest, and rebuild it with size limits, type checks from the file's own bytes, Pillow re-encoding, random storage names and safe download headers.
- Use SSH certificates instead of copying keys to every serverYou will run a small SSH certificate authority with ssh-keygen, log in to an Ubuntu 26.04 server with an eight-hour user certificate, give the server a host certificate so clients stop asking about fingerprints, and revoke a certificate the server then refuses.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials