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.
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.
| Tool | Question it answers | Weak spot |
|---|---|---|
| debsums, dpkg --verify | Have packaged system files changed? | Checksums live on the same host |
| rkhunter | Are there signs of a rootkit or altered binaries? | Needs a trusted baseline, and is noisy |
| ClamAV | Do any files match known malware? | Custom web shells often pass |
| Maldet | Are 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.
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
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.
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.
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.
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.
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 found | What it suggests | Sensible response |
|---|---|---|
| Malware only in one site's files | Application-level compromise | Clean the site, patch the entry point, rotate its credentials |
Changed binaries in /usr/bin or /usr/sbin | Possible root compromise | Rebuild from a clean image and restore data carefully |
| Unknown UID 0 account or SSH key | Attacker persistence | Assume root was reached, and plan a rebuild |
| Nothing, but symptoms continue | Scanners may have missed it | Check 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.