Linux Malware Detect

Published Updated

11 min read

Linux Malware Detect (LMD, the maldet command) is a free malware scanner built for web servers and shared hosting. This guide installs it from a verified release on Ubuntu, proves that detection works with a harmless test file, and covers scans, reports, quarantine, ClamAV, the daily cron job and real-time monitoring.


Overview

Linux Malware Detect is an open-source (GPLv2) malware scanner from R-fx Networks. It hunts for the stuff that ends up on web servers: PHP shells, JavaScript injectors, base64-encoded backdoors, IRC bots and other code dropped into user web folders.

Signatures come from the author's network edge intrusion detection data, user submissions and community sources. LMD checks files by hash (MD5 and SHA-256), by HEX patterns, by compound signatures and by YARA rules. It can also hand the job to ClamAV and feed ClamAV its own signatures.

It's one layer of server hardening, not a replacement for it.

The project is alive. Version 2.0.1, a large rewrite of the scan and monitor engines, shipped in April 2026, and the GitHub repository gets regular commits and issue triage. The signature set has its own version number in YYYYMMDDnnnnn form, so you can always see how fresh it is (more on that below).

This guide was tested with LMD 2.0.1 on Ubuntu 24.04 and 26.04 LTS, with notes for AlmaLinux and Rocky Linux at the end.

Installation

LMD isn't in the Ubuntu repositories. You install it from the release tarball with the bundled install.sh. All commands below run as a user with sudo.

Step 1: Install the dependencies

shell

1sudo apt update
2sudo apt install -y wget ca-certificates inotify-tools bsdextrautils

inotify-tools is needed for real-time monitoring. bsdextrautils provides the column command, which maldet uses to print the list of scan reports (minimal images don't have it).

Step 2: Download the release and verify the checksum

Download the release from the project's GitHub page over HTTPS and check its SHA-256 before you run anything as root:

shell

1VER=2.0.1
2wget https://github.com/rfxn/linux-malware-detect/releases/download/v${VER}/maldet-${VER}.tar.gz
3echo "26674c72208a4c32ae4ed8770a2b5c036b35c0894a4812450df11c5a53d7d8e5 maldet-${VER}.tar.gz" | sha256sum -c -

You should see maldet-2.0.1.tar.gz: OK. If you install a newer release, take its SHA-256 from the releases page: GitHub shows the digest next to each asset.

⚠️ Don't use the old maldetect-current.tar.gz download from the rfxn website. It still serves version 1.6.6, and its published .sha256 file doesn't match the archive.

That archive also contains two files that are not in the project's public source code, internals/cve-2026-41940 and internals/host_meta, plus a hidden block in install.sh. According to issue #498, on cPanel servers the installer runs cve-2026-41940 as root: it kills certain processes, quarantines files and can suspend a cPanel reseller account. host_meta adds a detailed host fingerprint to what LMD already sends to cdn.rfxn.com during signature updates. The report comes from an outside user, the maintainer hadn't answered it when we checked on November 6, 2026, and the purpose of the code isn't confirmed. What is certain: it's undocumented and not in the GitHub source. The GitHub release above doesn't contain these files.

If you installed LMD from the rfxn.com tarball before

Check whether the extra files are on the server:

shell

1ls -l /usr/local/maldetect/internals/cve-2026-41940 /usr/local/maldetect/internals/host_meta /usr/local/maldetect/cve-2026-41940.done
2grep -i cve-2026-41940 /usr/local/maldetect/logs/event_log

"No such file or directory" for all three files and no match in the event log mean this install didn't come from the affected tarball. If any of them exist:

  1. Remove LMD with sudo /usr/local/maldetect/uninstall.sh and install it again from the GitHub release as shown above.
  2. If cve-2026-41940.done exists, the script has already run. On a cPanel server, check WHM for suspended accounts (whmapi1 listsuspended) and look for files or services that stopped working around the install date.
  3. Turn off automatic version updates (step 4), so the daily cron job doesn't download the same tarball again.

Step 3: Run the installer

shell

1tar -xzf maldet-${VER}.tar.gz
2cd maldet-${VER}
3sudo ./install.sh

The installer copies LMD to /usr/local/maldetect, links the maldet command into /usr/local/sbin, adds cron jobs, installs a systemd unit for the monitor and downloads the first signature set. The end of the output looks like this:

shell

1maldet(476): {sigup} signature set update completed
2maldet(476): {sigup} 47,844 signatures (45,385 MD5 | 2,373 HEX | 86 CSIG | 3,706 YARA(no engine) | 0 USER)
3
4 Install path: /usr/local/maldetect
5 Config file: /usr/local/maldetect/conf.maldet
6 Exec file: /usr/local/maldetect/maldet
7 Exec link: /usr/local/sbin/maldet
8 Exec link: /usr/local/sbin/lmd
9 Cron.daily: /etc/cron.daily/maldet
10 Linux Malware Detect 2.0.1 installation complete

The main config file is /usr/local/maldetect/conf.maldet. Every option in it is commented.

Step 4: Switch off automatic version updates

By default the daily cron job also tries to update LMD itself (autoupdate_version="1"). In 2.0.1 that check pulls the same maldetect-current.tar.gz from the rfxn CDN. On our test server the update only stopped because the checksum didn't match:

shell

1maldet(9283): {update} version check shows latest but hash check failed, forcing update...
2maldet(9283): {update} unable to verify sha256sum of maldetect-current.tar.gz, please try again

Until the vendor sorts this out, turn version updates off and upgrade by hand from GitHub releases. Signature updates stay on:

shell

1sudo sed -i 's/^autoupdate_version="1"/autoupdate_version="0"/' /usr/local/maldetect/conf.maldet
2grep -E '^autoupdate_(version|signatures)=' /usr/local/maldetect/conf.maldet

Update malware signatures

shell

1sudo maldet -u

The installer adds /etc/cron.d/maldet-sigup, which runs the same update every 6 hours, and the daily cron job checks again. Downloads are verified by SHA-256 (you'll see verified sha256sum of maldet-sigpack.tgz in the output).

To see which signature set you have:

shell

1cat /usr/local/maldetect/sigs/maldet.sigs.ver

The first eight digits are the release date of the set. If that date is months old, keep it in mind when you read a clean report.

Test detection with EICAR

Before you trust a clean result, make sure the scanner actually finds something. EICAR is a standard, harmless antivirus test file that every scanner detects.

Create a test site with one clean page and one EICAR file, owned by the web server user:

shell

1sudo mkdir -p /var/www/example.com/public
2echo '<?php echo "hello from a clean page"; ?>' | sudo tee /var/www/example.com/public/index.php > /dev/null
3printf '%s' 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' | sudo tee /var/www/example.com/public/eicar.php > /dev/null
4sudo chown -R www-data:www-data /var/www/example.com

The ownership matters. LMD skips files owned by root (user or group) by default (scan_ignore_root="1"), because on a web server the interesting files belong to users and the web server.

A root-owned test file gives you a confusing "empty file list" result. To include root-owned files in one scan, add -co scan_ignore_root=0.

Scan files

Scan a whole directory

shell

1sudo maldet -a /var/www/example.com/public

shell

1maldet(804): {scan} scan completed on /var/www/example.com/public: files 2, malware hits 1, cleaned hits 0, time 4s
2maldet(804): {scan} scan report saved, to view run: maldet --report 261102-1322.804
3maldet(804): {scan} quarantine is disabled! set quarantine_hits=1 in conf.maldet or to quarantine results run: maldet -q 261102-1322.804

Every scan gets an ID (261102-1322.804 here). You'll use it for reports, quarantine and restore.

The ? character works as a wildcard, which is handy for per-user web roots on cPanel-style servers. Several paths go in one argument, separated by commas with no spaces:

shell

1sudo maldet -a /home/?/public_html
2sudo maldet -a /var/www/example.com/public,/home/alice/public_html

The exit code is 0 when nothing is found, 2 when there are hits and 1 on errors (for example, a path that doesn't exist). That makes maldet easy to wire into your own scripts and monitoring.

Scan only recent changes

-r scans files created or changed in the last N days:

shell

1sudo maldet -r /var/www/example.com/public 2

LMD matches on both the modification time and the inode change time. In our test, a file with its mtime pushed 10 days back with touch was still picked up by -r ... 1, so backdating a dropped web shell doesn't hide it from this scan.

Run long scans in the background

Large trees can take hours. Instead of keeping a terminal open, start the scan in the background:

shell

1sudo maldet -b -a /var/www

Progress goes to /var/log/maldet/event_log. The report shows up in the list when the scan finishes. sudo maldet -L lists running scans, and --pause, --stop and --kill with a scan ID control them.

By default LMD skips files larger than 2 MB and smaller than 24 bytes (scan_max_filesize and scan_min_filesize in the config).

Read scan reports

Show the latest report:

shell

1sudo maldet -e

shell

1SCAN ID: 261102-1322.804
2PATH: /var/www/example.com/public
3RANGE: all
4FILES: 2
5HITS: 1
6CLEANED: 0
7QUARANTINED: 0 (quarantine disabled)
8BY TYPE: SHA256(1)
9
10FILE HIT LIST:
11{SHA256}test.test.eicar.29805 : /var/www/example.com/public/eicar.php

The prefix in curly braces tells you which stage matched: {MD5} or {SHA256} for a hash, {HEX} for a pattern, {CSIG} for a compound signature, {YARA} for a YARA rule and {CAV} for ClamAV.

List all reports, or open a specific one:

shell

1sudo maldet -e list
2sudo maldet -e 261102-1322.804

For scripts and dashboards, the same report comes out as JSON:

shell

1sudo maldet --json-report 261102-1322.804

Quarantine and restore

Quarantine is off by default, so a scan only reports. To move the hits from a scan into quarantine:

shell

1sudo maldet -q 261102-1322.804

shell

1maldet(5189): {quar} 1 files quarantined [quarantine]

The file disappears from the site and lands in /usr/local/maldetect/quarantine/ with permissions 000. Next to it, a .info file keeps the original path, owner, mode and timestamps.

If it was a false positive, restore everything from that scan, or a single file by its quarantine name:

shell

1sudo maldet -s 261102-1322.804
2sudo maldet -s eicar.php.235877

The file comes back to the same path with its original owner, permissions and mtime.

To quarantine hits automatically, set it in the config:

shell

1sudo sed -i 's/^quarantine_hits="0"/quarantine_hits="1"/' /usr/local/maldetect/conf.maldet

Or only for one run: sudo maldet -co quarantine_hits=1 -a /var/www. Turn it on after a few scans have shown you no false positives on your own code. Moving a file a live site needs will break that site.

Add ClamAV as a scan engine

ClamAV adds its own large signature database on top of LMD's. With ClamAV installed, LMD uses it automatically (scan_clamscan="auto") and links its own signatures into ClamAV's database directory.

shell

1sudo apt install -y clamav clamav-daemon
2sudo systemctl enable --now clamav-freshclam

Wait until freshclam has downloaded the databases. Both main and daily must be there:

shell

1ls /var/lib/clamav/

Then start the daemon and let LMD re-link its signatures:

shell

1sudo systemctl enable --now clamav-daemon
2sudo maldet -u --force

Run the EICAR scan again. The output should say that the ClamAV engine is used, and the hit should be there:

shell

1maldet(13133): {scan} found clamav binary at /usr/bin/clamdscan, using clamav scanner engine...
2maldet(13133): {scan} scan completed on /var/www/example.com/public: files 2, malware hits 1, cleaned hits 0, time 6s

With a running clamd, LMD uses clamdscan, which is much faster than loading the databases for every scan with clamscan. The daemon needs about 1-1.5 GB of RAM.

⚠️ Always repeat the EICAR test after you add ClamAV.

In our test, ClamAV was installed but freshclam hadn't downloaded its databases yet. LMD still switched to the ClamAV engine, ClamAV loaded no signatures, and the scan reported malware hits 0 on the EICAR file without any error on screen.

If ClamAV can't be kept healthy on a server, set scan_clamscan="0" and LMD uses its own engine.

Without ClamAV, LMD's YARA rules show up as YARA(no engine). Installing the yara package (sudo apt install -y yara) turns on LMD's native YARA stage.

The daily cron scan

The installer adds /etc/cron.daily/maldet. Once a day it:

  1. Removes quarantine, session and temp data older than 21 days (cron_prune_days).
  2. Updates signatures (and LMD itself, unless you turned that off in Step 4).
  3. Scans files changed in the last day (scan_days="1").

The job detects cPanel, Plesk, DirectAdmin, ISPConfig, Virtualmin, HestiaCP and other panels and scans their web roots. On a plain server it scans /home?/?/public_html/, /var/www/ and /usr/local/apache/htdocs/. It also waits a random 1-999 seconds before starting, to spread the load on the update servers.

To add your own paths, append a line to the hook file that the daily job runs:

shell

1echo '/usr/local/sbin/maldet -b -r /srv/app 1 >> /dev/null 2>&1' | sudo tee -a /usr/local/maldetect/cron/custom.cron

If the inotify monitor is running, the daily job skips its scan and sends a daily report of monitor events instead.

Real-time monitoring with inotify

The monitor watches folders through the kernel inotify subsystem and scans every file that is created, changed or moved in, in batches every 15 seconds (inotify_sleep).

What it needs:

  • a kernel with CONFIG_INOTIFY_USER, which every current distribution kernel has;
  • the inotifywait command from inotify-tools (installed in Step 1);
  • enough inotify watches. LMD raises max_user_watches and max_user_instances itself, one watch per directory. Inside a container these limits belong to the host kernel, so set them on the host.

Step 1: List the folders to watch

One path per line:

shell

1printf '%s\n' /var/www/example.com/public /home/alice/public_html | sudo tee /usr/local/maldetect/monitor_paths

You can also pass paths straight to maldet -m, separated by commas with no spaces (/var/www,/srv/app). With a space after the comma, the second path is silently dropped. A special mode, users, watches the public_html and public_ftp folders of every user with a UID of 500 or higher, plus /tmp, /var/tmp and /dev/shm.

Step 2: Run the monitor as a systemd service

The installer ships a maldet unit that reads the mode from /etc/default/maldet (on RHEL-family systems, /etc/sysconfig/maldet). The default there is users. Point it at your file:

shell

1sudo sed -i 's|^MONITOR_MODE=.*|MONITOR_MODE="/usr/local/maldetect/monitor_paths"|' /etc/default/maldet
2sudo systemctl enable --now maldet
3systemctl status maldet

shell

1● maldet.service - Linux Malware Detect monitoring - maldet
2 Active: active (running) since Mon 2026-11-02 13:32:59 UTC; 15s ago
3 ├─14278 bash /usr/local/maldetect/maldet --monitor /usr/local/maldetect/monitor_paths
4 ├─14399 /usr/bin/inotifywait -r --fromfile /usr/local/maldetect/sess/.inotify.paths.oDvwwz ...

⚠️ Don't use maldet -b -m to start the monitor in the background. In 2.0.1 it starts and exits a second later with existing monitor process detected (it finds its own PID file).

The bug is tracked in issue #505. The systemd service runs the monitor in the foreground and isn't affected.

Step 3: Check that it catches an upload

With quarantine_hits="1", drop an EICAR file into a watched folder as the web server user:

shell

1printf '%s' 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' | sudo -u www-data tee /var/www/example.com/public/upload.php > /dev/null
2sleep 30
3sudo grep -E '\{hit\}|\{quar\}' /var/log/maldet/event_log | tail -2

shell

1maldet(14278): {hit} 1 malware hits recorded [clamav]
2maldet(14278): {quar} 1 files quarantined [clamav]

In our test the file was quarantined 11 seconds after it was written. Raw inotify events are in /var/log/maldet/inotify_log. To stop the monitor, run sudo maldet -k or sudo systemctl stop maldet.

What LMD does not do

LMD is good at one job: finding known malicious files in web folders. Be clear about the rest.

  • It's a signature scanner. It finds what is in its signature sets, plus some obfuscation heuristics. New or custom malware, and anything its signatures don't cover yet, gets through. A clean report is not proof of a clean server.
  • It's not EDR. It doesn't watch processes, network connections, logins or memory, and it won't stop an attacker who is already running code. Fileless attacks never touch its folders.
  • It's not a rootkit scanner for the operating system. It deliberately skips root-owned files by default and focuses on user and web content.
  • It doesn't fix the hole. If a web shell appeared, something let it in: an outdated plugin, a weak password, writable code folders. Find and close that, or the file will be back tomorrow.

Use it together with patching, least-privilege file permissions, a hardened /tmp, a web application firewall, centralized logs and, for anything that matters, an EDR agent.

RHEL, AlmaLinux and Rocky Linux

The same steps work with three changes:

shell

1sudo dnf install -y epel-release
2sudo dnf install -y wget inotify-tools util-linux
  • inotify-tools comes from EPEL.
  • The monitor service reads MONITOR_MODE from /etc/sysconfig/maldet instead of /etc/default/maldet.
  • The web server user is usually apache (or nginx), not www-data.

We ran the install, the EICAR scan and the monitor start on AlmaLinux 10 and Rocky Linux 9 with the same results as on Ubuntu.

Remove LMD

shell

1sudo /usr/local/maldetect/uninstall.sh

It asks for confirmation and removes LMD, its cron jobs, the systemd unit and all quarantine data.

If you'd rather have someone else watch your servers, our team does security hardening and compliance for cloud and hosting infrastructure.

Alex Kondratiev

Alex Kondratiev

Founder and CEO of ITsyndicate. DevOps engineer with 15+ years in cloud infrastructure, Infrastructure as Code, Kubernetes and automation, focused on secure, scalable and resilient systems.

More about Alex

Stay online.
Stay in command.