Security
Difficulty: Intermediate
3 min read

RKHunter: Rootkit Detection on Linux

A tutorial to install and configure RKHunter (Rootkit Hunter), a tool for detecting rootkits and backdoors on Linux.

Back to tutorials
What is RKHunter?
RKHunter (Rootkit Hunter) is a security scanner for POSIX systems that looks for rootkits, backdoors and local exploits. It does this by comparing the SHA-256 hashes of important system files against known-good values, by looking for incorrect file permissions, suspicious strings in kernel modules, and by running specific tests for the various operating systems.

Why use RKHunter?

  • Post-compromise detection: Helps determine whether a system has been compromised by a rootkit.
  • Security audit: Part of a regular security audit to verify system integrity.
  • Lightweight and simple: Easy to install and use from the command line.

Prerequisites

  • A Linux server (Ubuntu/Debian, CentOS/RHEL, etc.).
  • Root access or sudo privileges.

Installation

# On Debian / Ubuntu
sudo apt-get update
sudo apt-get install -y rkhunter

# On CentOS / RHEL (via the EPEL repository)
sudo yum install -y epel-release
sudo yum install -y rkhunter

Configuration and first run

Step 1: Update the databases

Before the first scan, it is crucial to update RKHunter's signatures.

sudo rkhunter --update

Step 2: Populate the file properties

RKHunter needs to create a "baseline" of your system, that is, a database of the current state of your files. This command must be run on a system that you know to be "clean".

sudo rkhunter --propupd

This database will be used during future scans to detect changes.

Step 3: Run the first scan

Run the check command. The --check option starts the scan, and --sk (skip-keypress) avoids having to press "Enter" after each section.

sudo rkhunter --check --sk
Handling Warnings
On the first scan, it is almost certain that you will get several warnings. Most of them are false positives caused by the specific configuration of your system. Your job is to examine them one by one.

Analyzing the report and handling false positives

The scan report is located in /var/log/rkhunter.log.

sudo less /var/log/rkhunter.log

Look for lines containing `[ Warning ]`. For each warning, you need to determine whether it is a real problem or a false positive.

Example of a common false positive: "The file ` /usr/sbin/unhide` was found. It is a rootkit detection tool."

If you installed `unhide` yourself, this is a false positive. You can tell RKHunter to ignore it by editing its configuration file /etc/rkhunter.conf.

sudo nano /etc/rkhunter.conf

Find the appropriate directive (e.g. `ALLOW_SSH_ROOT_USER` or `SCRIPTWHITELIST`) and add the file or parameter you want to whitelist.

After adding exceptions, run rkhunter --propupd again to update the baseline, then a new rkhunter --check --sk to verify that the warnings have disappeared.

Automating scans

It is essential to scan your system regularly. You can easily create a cron job for this.

sudo nano /etc/cron.daily/rkhunter-scan

Add the following content for a daily scan:

#!/bin/sh
(
/usr/bin/rkhunter --update
/usr/bin/rkhunter --cronjob --report-warnings-only
) | mail -s "RKHunter report for $(hostname)" [email protected]

Make this script executable:

sudo chmod +x /etc/cron.daily/rkhunter-scan
Combine with Chkrootkit
RKHunter is often used in tandem with another tool called chkrootkit. The two tools have slightly different detection methods, and using them together provides better coverage.

Conclusion

RKHunter is an essential security tool that should be part of the basic arsenal of any Linux system administrator. Although it requires some initial effort to sort through the false positives, once configured and automated it provides valuable and silent monitoring of your system's integrity. It is your "canary in the coal mine", which will alert you if anything suspicious happens.

Written by

Morgann Riu

Cybersecurity and Linux administration expert. I share my knowledge through free tutorials and training to help system administrators and developers secure their infrastructures.

Frequently asked questions

My first scan reports several warnings, have I been compromised?
In the vast majority of cases, no. The first run produces warnings because RKHunter does not yet know the specifics of your installation: extra packages, custom scripts, unusual SSH options. Open /var/log/rkhunter.log, isolate every [ Warning ] line and decide for each one whether the item is legitimate. The real signal is a warning you cannot explain by anything you did yourself.
When should I re-run rkhunter --propupd, and what is the risk?
After every legitimate change to the system state: package upgrades, installing a tool, adding exceptions to /etc/rkhunter.conf. The command recomputes the file properties database that later scans use as their reference. The danger is running it on an already compromised system: the binaries the attacker modified then become the new normal and will never be flagged again. Only run it against a state you are confident about.
Why does RKHunter flag a tool such as /usr/sbin/unhide?
Because those utilities are themselves rootkit detection tools, and their presence on a machine where the administrator never installed them is a signal in itself. If you installed it yourself, it is a false positive: whitelist it in /etc/rkhunter.conf, re-run rkhunter --propupd to refresh the baseline, then rkhunter --check --sk to confirm the warning is gone. If you never installed it, that one deserves a real investigation.
Does RKHunter protect the server, and should I also install chkrootkit?
RKHunter protects nothing: it merely observes, after the fact, that a system file changed or that something suspicious is present. It complements real hardening (firewall, SSH, patching) and never replaces it. chkrootkit is often run alongside it because its detection methods differ slightly: running both widens the coverage, and a rootkit that slips past one may well be caught by the other.
How do I get reports automatically without drowning in email?
Create a script in /etc/cron.daily/, for example rkhunter-scan, chaining rkhunter --update then rkhunter --cronjob --report-warnings-only, and pipe the output to mail. The --cronjob flag suppresses the interactive output and --report-warnings-only restricts the content to warnings alone, so a healthy system only generates a very short message. Do not forget chmod +x on the script, otherwise cron will never run it.

Share this tutorial

Did you enjoy this article?

Comments

Checklist Sécurité Linux

30 points essentiels pour sécuriser un serveur Linux. Recevez aussi les nouveaux tutoriels par email.

Pas de spam. Désabonnement en 1 clic.