Security 6 min read

Ubuntu Malware Scanner Guide: How to Check a Server

No single tool answers whether an Ubuntu server is clean. Four free ones, used in the right order, get you much closer, if you know what each can't see.

By BashPilot Team
BashSecure Malware & vulnerability protection Scan, find and remove malware across every hosted account. Explore BashSecure

Looking for one Ubuntu malware scanner that settles the question is the usual first mistake. A compromised server has at least two places to check: the operating system and the websites it hosts. The tools that are good at one are mostly blind to the other. This guide uses four free tools in a deliberate order, and explains what a clean result from each one can and cannot tell you.

Before you scan anything

If you believe the machine is compromised, take a provider snapshot first. Scans change file access times and installing packages writes to disk, so a snapshot preserves the state you may need later. It also gives you something to scan safely from another machine, which matters because a serious intruder can make tools on the infected host lie.

ToolQuestion it answersWeak spot
debsums, dpkg --verifyHave packaged system files changed?Checksums live on the same host
rkhunterAre there signs of a rootkit or altered binaries?Needs a trusted baseline, and is noisy
ClamAVDo any files match known malware?Custom web shells often pass
MaldetAre there known web threats like PHP shells?Default settings skip root-owned files

Check the operating system's own files

Ubuntu keeps a checksum for most packaged files, which gives you a fast way to spot a modified /usr/bin/sudo or a tampered library.

list changed package files
sudo apt install debsums
sudo debsums -c
sudo debsums -ce
sudo dpkg --verify

debsums -c reports changed files and -ce does the same for configuration files, which you would expect to differ on any server that has been set up. In dpkg --verify output, a line such as ??5?????? /usr/bin/example means the content no longer matches, and a c before the path marks a config file. A changed /etc/nginx/nginx.conf is normal. A changed binary in /usr/bin or /usr/sbin is not.

Look for rootkits with rkhunter

run a check and show warnings only
sudo apt install rkhunter
sudo rkhunter --check --sk --rwo
sudo less /var/log/rkhunter.log

Expect some warnings on a healthy server, often from scripts that replaced binaries or from unusual but harmless hidden files. The detail for each one is in the log. Most guides tell you to run rkhunter --propupd right after installing, and on a fresh, trusted server that is correct, because it stores a baseline for future comparisons.

On a server you are investigating, it is exactly wrong. The rkhunter manual warns that after --propupd, it will assume a changed file is genuine. Run it on a suspect machine and you have just approved the attacker's binaries as your new normal.

Scan the web files with ClamAV

Most compromises on a web server live in application code, so this is where you spend your time. On Ubuntu the clamav package brings in clamav-freshclam, which keeps signatures up to date as a background service.

install, check signatures and scan
sudo apt install clamav
sudo systemctl status clamav-freshclam --no-pager
nice -n 19 ionice -c3 sudo clamscan -r -i -l /root/clamscan-web.log /var/www
echo "exit code: $?"

If you run freshclam by hand and it complains that its log file is locked, the service is already handling updates, so let it be. The clamscan exit code is the part to read carefully: 0 means nothing was found, 1 means malware was found, and 2 means errors occurred. A 2 means the check is incomplete and should not be recorded as clean.

Add Maldet for web-specific threats

Linux Malware Detect was designed around shared hosting threats such as PHP shells and injected JavaScript, and it uses ClamAV's engine when that is available. Install it from the project's repository.

install from the project's repository
git clone https://github.com/rfxn/linux-malware-detect.git
cd linux-malware-detect
sudo ./install.sh
sudo maldet -u

Here is the detail that catches people out. Maldet's scan_ignore_root setting defaults to 1, so it skips files owned by root. On a plain Ubuntu server, website files are often owned by root because someone deployed them with sudo. A default scan of /var/www could then finish quickly and find nothing because it barely looked. Override it for this run.

scan including root-owned files, then read the report
sudo maldet -co scan_ignore_root=0 -a /var/www
sudo maldet -e

Maldet does not quarantine by default (quarantine_hits is 0), which is what you want at this stage. Read the report first. If a hit is confirmed, maldet -q SCANID quarantines that scan's files and maldet -s SCANID restores them. The ClamAV vs Maldet comparison goes deeper on using the two together.

Check the things scanners do not look at

Persistence often has nothing to do with a suspicious file. It is a cron entry, a service, an SSH key or a new account. These checks take a couple of minutes and catch a lot.

accounts, keys, schedules, services and connections
awk -F: '$3 == 0' /etc/passwd
sudo find /root /home -name authorized_keys -exec ls -l {} \;
sudo ls -la /etc/cron.d /var/spool/cron/crontabs
systemctl list-unit-files --type=service --state=enabled
sudo ss -tupn
sudo find /var/www -type f -name '*.php' -mtime -14

The first line should print only root. Read each authorized_keys file and account for every key. Look for enabled services you do not recognise and outbound connections to addresses you cannot explain. If a site runs WordPress, verify it against the official release with WP-CLI checksums.

Decide what to do with the results

What you foundWhat it suggestsSensible response
Malware only in one site's filesApplication-level compromiseClean the site, patch the entry point, rotate its credentials
Changed binaries in /usr/bin or /usr/sbinPossible root compromiseRebuild from a clean image and restore data carefully
Unknown UID 0 account or SSH keyAttacker persistenceAssume root was reached, and plan a rebuild
Nothing, but symptoms continueScanners may have missed itCheck logs and outbound traffic, and test from a clean host

Rebuilding feels drastic, but once root is in doubt it is the only result you can trust. Restore site content from a backup taken before the compromise, and change every password and key the old server held.

Moving from occasional scans to ongoing protection

This routine is a good investigation, but it runs only when someone remembers. BashSecure for Ubuntu works on the application layer without needing a control panel. It discovers web roots, reads the content of website files, records filesystem changes as they happen, and links dangerous PHP behaviour to the virtual host and script involved. Live Defense can run in Log mode before Kill mode is enabled, and confirmed threats move to quarantine with their path, owner and permissions preserved.

Share LinkedIn X
Questions

Frequently asked questions

What is the best malware scanner for Ubuntu Server?

No single tool covers everything. Use `debsums` for changed system files, `rkhunter` for rootkit signs, and ClamAV with Maldet for website files. On a web server, most compromises are in application code, so the ClamAV and Maldet checks usually matter most, followed by a manual review of accounts and scheduled tasks.

Does Ubuntu need antivirus?

A server that hosts websites, uploads or mail benefits from malware scanning, because the common risk is compromised application code and not a desktop virus. Ubuntu's package updates protect the operating system, but they cannot tell you that a website's plugin folder now contains a backdoor.

Why does Maldet find nothing on my Ubuntu server?

Check file ownership. Maldet's `scan_ignore_root` setting defaults to 1, so root-owned files are skipped. If your site was deployed as root, a default scan may check very little. Run `maldet -co scan_ignore_root=0 -a /var/www` to include those files in the scan.

Should I run rkhunter --propupd after finding a warning?

Not until you have explained the warning. The `--propupd` option records current file properties as the trusted baseline, and rkhunter then assumes changed files are genuine. On a suspect server this would hide the evidence. Use it only on a system you trust, such as right after a clean install or a verified update.

Can I trust scan results on a hacked server?

Only partly. An attacker with root access can alter binaries, checksum lists and even the scanning tools. Treat positive findings as real, and clean results as weak evidence. For higher confidence, snapshot the disk and examine it from a clean machine, and rebuild if system files appear to have been changed.

Put your servers on autopilot.

Connect a server in about a minute. The first week is on us.