File integrity monitoring on Linux usually means a nightly AIDE run that nobody reads, which tells you a binary changed only after an attacker has already used it. Linux has three very different integrity layers: AIDE compares files against a stored baseline, the kernel's Integrity Measurement Architecture (IMA) and Extended Verification Module (EVM) measure and appraise files as they are opened, and Keylime uses the TPM to prove those measurements to a remote verifier. Used together they move you from "detect later, on the same host the attacker controls" to "prevent or prove, from somewhere else". This guide explains how each layer works, what to monitor, how to roll them out without breaking patching, and how they meet PCI DSS and NIST SI-7 requirements. It is for Linux platform engineers, detection engineers and auditors; basic AIDE set-up is covered in the Linux Server Hardening Guide and is not repeated here.
Key takeaways
- AIDE detects, IMA can prevent. Red Hat's own comparison is that AIDE detects modifications on the local system only, while IMA can detect and prevent changes and can support remote verification.
- A baseline on the attacked host is not evidence. If the AIDE database, configuration and binary live on the same writable disk as the files they check, root can rewrite all three; keep them read-only or off-host.
- Remote attestation removes the trust problem. Keylime has the TPM sign the IMA measurement list (PCR 10) and boot log, so a verifier on another host decides whether the machine is still in a known state.
- Change detection is only as good as change control. Every package update changes hundreds of files; without a link from FIM alerts to approved changes, alerts are either ignored or the baseline is updated blindly.
- Integrity is not trustworthiness. FIM tells you a file differs from the baseline, not whether the baseline was clean: a backdoored package installed through normal patching passes every check.
The three layers and when to use each
| Layer | How it works | When it checks | Can it block? | Trust anchor | Best fit |
|---|---|---|---|---|---|
| AIDE | Hashes and attributes of selected paths compared with a stored database | On schedule (cron or systemd timer) | No | The database and binary, wherever you store them | Every server; compliance evidence; configuration drift |
| Package verification | Compare installed files with the package manager's recorded digests (for example rpm -Va) | On demand | No | Signed package metadata in the local database | Quick triage of system binaries after an alert |
| IMA measurement | Kernel hashes files on exec, mmap or open per policy and appends to a measurement list, extending TPM PCR 10 | Every access covered by policy | No (measure only) | TPM, if present | Feeding remote attestation; forensic record of what ran |
| IMA appraisal and EVM | Kernel compares a file's hash or signature in security.ima with its content, and EVM protects the security extended attributes | Every access covered by policy | Yes, in enforce mode | Keys on the .ima and .evm keyrings | Immutable appliances, high-assurance servers, signed builds |
| Keylime | Remote verifier checks TPM quotes against the IMA log and measured boot log using a runtime policy | Continuously (polling) | Indirectly, through revocation actions | TPM endorsement keys and your CA | Fleets that must prove state to someone other than the host |
Decision guidance
- Small estate, general servers: AIDE with an off-host database and a SIEM alert on non-zero exit status covers most compliance needs. Add package verification to your triage runbook.
- Regulated or high-value servers: add IMA measurement and Keylime so the integrity decision is made off the host. This needs a TPM 2.0 (physical or, with caveats, virtual) and a verifier service.
- Immutable or appliance-like systems: IMA appraisal in enforce mode is realistic only where you control the build and can sign every executable; general-purpose servers that install third-party software usually stay in measurement or
logmode. - Containers and short-lived VMs: per-instance AIDE baselines add little; verify the image at build and admission time, and use IMA and Keylime on the long-lived hosts that run them. See the Server Build and Golden Image Hardening Guide.
Running AIDE properly
What to watch
The AIDE configuration (/etc/aide.conf on RHEL) is a set of rules: a path regular expression followed by an attribute group. AIDE defines default groups, for example R (permissions, file type, inode, links, owner, group, size, mtime, ctime, a hash and extended attributes), L (the same without content hash, for logs) and > for growing files. Rules can exclude paths with ! (recursive) and, in AIDE 0.19 and later, - (non-recursive). Every rule must start with an explicit /.
| Path class | Examples | Suggested group | Attack it reveals |
|---|---|---|---|
| System binaries and libraries | /usr/bin, /usr/sbin, /usr/lib64, /boot | Full content hash (R) | T1554 Compromise Host Software Binary, T1014 Rootkit |
| Loader and preload configuration | /etc/ld.so.preload, /etc/ld.so.conf.d | Full content hash | T1574.006 Dynamic Linker Hijacking |
| Identity and authentication files | /etc/passwd, /etc/shadow, /etc/sudoers.d, /etc/pam.d, /etc/ssh/sshd_config | Full content hash | Backdoor accounts, PAM modules, SSH configuration changes |
| Keys and credentials | /root/.ssh/authorized_keys, service account authorized_keys, keytabs | Full content hash | T1098.004 SSH Authorized Keys |
| Persistence locations | /etc/systemd/system, /etc/cron.d, /var/spool/cron, /etc/modules-load.d | Full content hash | T1543.002 Systemd Service, T1053.003 Cron, T1547.006 Kernel Modules |
| Application code and web roots | /opt/<app>, /var/www | Full content hash, with exclusions for caches and uploads | Web shells, tampered application code |
| Logs | /var/log | Growing (>) or L, never full hash | Truncation or deletion of logs |
Service account keys and keytabs are non-human credentials: an unexpected new authorized_keys entry for a deployment account is as serious as a new root password. See the Linux Service Accounts and Keytab Management Guide and the SSH Key Management Guide.
Making results usable
- Exit status:
aide --checkreturns 1 for new files, 2 for removed files and 4 for changed files, added together (so 7 means all three), with 14 to 25 reserved for errors such as configuration (17) or database (24) problems. Alert on any non-zero value, and treat error codes as a monitoring failure, not a clean result. - Output to the SIEM:
report_urlcan write to a file or tosyslog:<facility>, and newer AIDE releases (0.18 and later) supportreport_format=jsonorndjson, which parse far more reliably than plain text. Check the version your distribution ships. - Frequency: Red Hat states that at a minimum AIDE should run weekly, and daily is better. Its example cron entry is
05 4 * * * root /usr/sbin/aide --check. - Protect the baseline: store the database, configuration and
/usr/sbin/aideon read-only media or pull them from a central store at check time. Therhel-system-roles.aideAnsible role can initialise the database and fetch it to the control node (aide_db_fetch_dir), which keeps the trusted copy off the host. - Update deliberately:
aide --updatewrites a new database that only takes effect when you rename it. Run it after verifying the change, from the same pipeline that applied the change, never as a reflex to silence alerts.
IMA and EVM: integrity in the kernel
How IMA works
IMA is configured with a policy of rules in the form action [condition ...], where actions include measure, appraise, audit and their dont_ forms, and conditions include hooks such as BPRM_CHECK (program execution), FILE_MMAP or MMAP_CHECK (executable mappings), FILE_CHECK, MODULE_CHECK, FIRMWARE_CHECK, KEXEC_KERNEL_CHECK and KEY_CHECK. Measurements are listed in /sys/kernel/security/ima/ascii_runtime_measurements, and on a system with a TPM each one extends PCR 10, which makes the list tamper-evident.
| Kernel parameter | Values (kernel documentation) | Meaning |
|---|---|---|
ima_policy= | tcb, appraise_tcb, secure_boot, fail_securely, critical_data | tcb measures executed programs, executable mappings and files read by root; appraise_tcb appraises files owned by root; secure_boot appraises kexec images, modules, firmware and policy by signature |
ima_appraise= | off, enforce, fix, log (default enforce) | fix labels files without blocking; log records failures; enforce denies access to files that fail appraisal |
ima_template= | ima, ima-ng, ima-ngv2, ima-sig, ima-sigv2 (default ima-ng) | ima-sig includes file signatures in the log so a verifier can check them |
ima_hash= | For example sha256, sha512 (kernel default sha1) | Set an explicit modern algorithm; signatures must use the same algorithm IMA measures with |
evm= | fix | Permits security.evm to be updated regardless of integrity status, for initial labelling |
Appraisal and signatures
- Hash or signature: appraisal compares file content with the value stored in the
security.imaextended attribute. A plain hash only proves the file has not changed since labelling; a signature (appraise_type=imasig, appendedmodsigor format v3sigv3) proves who approved it. - Signing: files are signed with
evmctl ima_signfrom the ima-evm-utils package, and the public key must be loaded on the.imakeyring. Keylime's documentation warns that signing with a different hash algorithm from the one IMA measures with produces invalid signatures. - EVM: protects security extended attributes (including
security.imaand SELinux labels) against offline tampering, either with an HMAC from a trusted or encrypted key in the kernel keyring or with an asymmetric signature. Setting bit 31 in<securityfs>/evmprevents further runtime change of the EVM policy. - fs-verity: the policy option
digest_type=veritylets IMA use an fs-verity file digest instead of a full file hash, which suits large read-only files.
The signing keys are the root of trust for the whole fleet. Hold them in an HSM or a tightly controlled signing service, not on build agents. See the Linux Package Signing and Repository Trust Guide.
Keylime: remote attestation for Linux fleets
Keylime moves the integrity decision off the monitored host. Red Hat Enterprise Linux 9 documents four parts: an agent on each monitored system, a verifier that performs initial and periodic checks, a registrar that holds the agent database and TPM vendor public keys, and the keylime_tenant utility used to provision agents and policies.
| Component | RHEL 9 package and default port | Security notes |
|---|---|---|
| Verifier | keylime-verifier, TCP 8881, configuration in /etc/keylime/verifier.conf.d/ | Control interface uses mutual TLS; by default it generates its CA under /var/lib/keylime/cv_ca/, which you should replace with your own PKI for production |
| Registrar | keylime-registrar, TCP 8890 for agents and 8891 (TLS) for verifier and tenant | Database defaults to SQLite; PostgreSQL, MySQL and MariaDB are supported for scale |
| Agent | Runs on each monitored host with access to the TPM | Reports TPM quotes, the IMA log and the boot event log |
| Tenant | keylime_tenant | Whoever can run it with valid certificates can change runtime policies: treat it as privileged |
- Runtime integrity: the verifier checks the IMA measurement list against a runtime policy (formerly called an allowlist) of expected hashes plus an exclude list of regular expressions, and validates it against TPM quotes of PCR 10. A file not in the policy, or a file with the wrong hash, puts the agent into a failed state.
- Measured boot: with a measured boot reference state, the agent also sends
/sys/kernel/security/tpm0/binary_bios_measurements, the verifier replays it against PCRs 0 to 9 and 11 to 14, and compares it with the reference using a measured boot policy. - Policy creation is the hard part: Keylime's documentation advises generating the policy in a secure, ideally isolated environment and signing it. Build it from your signed packages and image pipeline, not from a running production host that may already be compromised.
- Virtual TPMs: Red Hat notes that Keylime in a VM or with a virtual TPM depends on the integrity of the underlying host.
- Machine identity: each agent is a non-human identity with a TPM-bound key and a certificate; enrolment, renewal and revocation of agent certificates need an owner. See the IoT Device Identity with TPM and DICE Guide.
Implementation roadmap
- Scope and baseline (weeks 1 to 2): classify servers by tier, list the critical paths per role using the table above, and write an AIDE configuration per role. Store the configuration in version control.
- AIDE everywhere (weeks 2 to 6): deploy with configuration management, initialise the database from a freshly built, patched host, keep the trusted copy off-host, and schedule daily checks. Forward exit codes and reports to the SIEM.
- Connect to change control: have the patching or deployment pipeline run
aide --checkbefore a change andaide --updateafter verification, attaching the diff to the change record. Unexplained differences become incidents. - IMA measurement pilot: on a pilot ring, boot with
ima_policy=tcbor a custom policy loaded from/etc/ima/ima-policy, setima_hash=sha256, and measure the performance cost and log volume for a full business cycle. - Keylime for high-value tiers: deploy the verifier and registrar on hardened hosts with your own CA, generate runtime policies from the image pipeline, start with alerting only, then define revocation actions (for example removing the host from a load balancer or revoking its certificates).
- Appraisal where you control the build: sign executables in the build, run
ima_appraise=fixto label, thenlogto find unsigned or failing files, and only thenenforce. - Rollback: keep a boot entry without the IMA appraisal parameters and test console access before enforcing; for Keylime, removing an agent with
keylime_tenant -c deletestops attestation without touching the host. Never roll back by updating the baseline from the suspect host.
Detection and measurement
- Alert on: AIDE changes outside a change window; AIDE error exit codes or missing reports (the check itself was disabled, which maps to ATT&CK T1685 Disable or Modify Tools); Keylime agent failed states; new
authorized_keysentries; changes to/etc/ld.so.preload; unexpected kernel module measurements. - Correlate with auditd: AIDE says what changed, auditd watch rules on the same paths say who changed it and with which process. See the Linux Logging and auditd for Defenders Guide.
- Triage quickly: on an alert, compare the file with its package (
rpm -Vf <file>or the distribution equivalent), check the IMA log for when it was first executed, and preserve the host before updating anything. See the Linux Forensics Guide.
Metrics
- Coverage: percentage of in-scope servers with a successful integrity check in the last 24 hours (target 100 percent for PCI and Tier 0).
- Silent failures: number of hosts whose check returned an error code or no report (target zero, investigated within one day).
- Explained change rate: percentage of integrity differences matched to an approved change record (trend towards 100 percent).
- Time to triage: median time from an unexplained difference to a decision (benign or incident).
- Attested fleet: percentage of high-value servers under Keylime attestation with a runtime policy built from the pipeline.
Framework and compliance mapping
| Requirement | What it asks | Linux control |
|---|---|---|
| PCI DSS v4.0.1 Requirement 11.5.2 | A change-detection mechanism such as FIM that alerts on unauthorised modification of critical files and compares them at least weekly | AIDE daily with SIEM alerting; Keylime for continuous checks |
| NIST SP 800-53 Rev 5 SI-7, SI-7(1), SI-7(6), SI-7(7) | Integrity verification, integrity checks, cryptographic protection, integration with incident response | AIDE hashes; IMA signatures; FIM alerts feeding the incident process |
| NIST SP 800-53 Rev 5 SI-7(9) | Verify boot process | Secure Boot plus Keylime measured boot attestation |
| NIST SP 800-53 Rev 5 CM-3, AU-9 | Configuration change control; protection of audit information | Linking updates to change records; FIM on log configuration |
| NIST CSF 2.0 PR.DS-01, PR.PS-01, DE.CM-09 | Data at rest integrity, configuration management, monitoring of software and runtime environments | All three layers |
| CIS Controls v8.1 | Control 4 Secure Configuration; Control 8 Audit Log Management | Baselines and logging of integrity results |
| ISO/IEC 27001:2022 Annex A | A.8.9 Configuration management; A.8.16 Monitoring activities | Baselines and alerting |
| MITRE D3FEND | D3-FIM File Integrity Monitoring; D3-TBI TPM Boot Integrity | AIDE and IMA; Keylime measured boot |
For the broader secure boot chain that IMA and Keylime build on, see the Linux Secure Boot and Shim Guide.
Common failure patterns
- Baseline on the same disk: the AIDE database and binary are writable by root on the host, so an attacker with root updates the baseline after planting a backdoor and every later check is clean.
- Reflex updates: operators run
aide --updateafter every alert to make it go away, which turns FIM into a record of whatever the attacker left behind. - Checking the wrong paths: the default configuration covers system binaries but not
/optapplications, web roots or service accountauthorized_keys, which is where real intrusions persist. - Silent failure treated as success: a cron job that stopped, a database that failed to load (exit code 24) or a report that never reached the SIEM looks exactly like "no changes" unless you alert on missing results.
- Allowlists built from production: generating a Keylime runtime policy or AIDE baseline from a live host bakes any existing compromise into the trusted state.
- Enforcing IMA appraisal too early: switching to
ima_appraise=enforcebefore every executable, library and module is signed leaves a server unable to boot or run its software.
Lessons from incidents
The XZ Utils backdoor shows the limit of file integrity monitoring. The malicious code shipped inside signed, legitimate release tarballs for XZ Utils 5.6.0 and 5.6.1, so a system updated through normal package channels would have recorded the backdoored liblzma as its new, trusted baseline. AIDE and IMA would both have reported the file as changed during the update and then accepted it. FIM proves that files match what you approved; it cannot tell you that what you approved was clean. That job belongs to supply chain controls, reproducible builds and behavioural detection (the backdoor was found through unusual CPU use during SSH logins). See the Software Supply Chain Security Guide.
Practitioner checklist
- Define critical paths per server role, including
/optapplications, web roots, service account keys and persistence locations. - Initialise AIDE baselines from freshly built hosts and keep the database, configuration and binary off-host or read-only.
- Run AIDE at least daily, send JSON or syslog output to the SIEM and alert on any non-zero exit code and on missing reports.
- Run
aide --updateonly from the change pipeline after verification, attaching the diff to the change record. - Pilot IMA measurement with
ima_hash=sha256and measure the performance and log impact before wider use. - Deploy Keylime for high-value tiers with your own CA and runtime policies built from the image pipeline.
- Sign executables in the build and move IMA appraisal through
fixandlogbeforeenforce. - Protect IMA and EVM signing keys in an HSM or controlled signing service.
- Correlate integrity alerts with auditd and package verification in a written triage runbook.
- Report coverage, silent failures and explained change rate monthly.
Standards and references
- Red Hat: Checking integrity with AIDE (RHEL 9 Security Hardening)
- Red Hat: Ensuring system integrity with Keylime (RHEL 9 Security Hardening)
- Linux kernel documentation: IMA policy ABI
- Linux kernel documentation: Kernel parameters (ima_policy, ima_appraise, evm)
- AIDE project: aide.conf manual
- Keylime project: Keylime documentation
- NIST: SP 800-53 Rev. 5
- MITRE D3FEND: File Integrity Monitoring
Related NHI Mgmt Group resources: Linux Server Hardening Guide · Red Hat Enterprise Linux Security Hardening Guide · fapolicyd and Linux Application Allowlisting Guide · Linux Detection and Response Guide