Linux VPS7 min read•Last updated: •By SkyRain Cloud Team

How to Scan a Linux Server for Malware with ClamAV

Linux servers rarely get "viruses" in the desktop sense, but they do get malware: PHP web shells uploaded through an outdated plugin, cryptominers dropped after a weak SSH password, and infected files that a website then serves to visitors. ClamAV is the free, open-source antivirus engine most Linux admins reach for when they need to check a server for these problems.

This guide installs ClamAV on Ubuntu or Debian, keeps its signatures current, runs fast and thorough scans, schedules them, and explains honestly what ClamAV can and cannot catch, plus what to do when it finds something.

Quick answer

Install ClamAV with sudo apt install clamav clamav-daemon; the clamav-freshclam service then keeps virus signatures updated. Scan a folder with sudo clamscan -r -i /var/www, or use clamdscan --multiscan --fdpass /var/www for faster scans through the daemon. Schedule a daily scan with cron and log the results. ClamAV detects known malware by signature, so combine it with updates, file-integrity checks and good access control. Budget roughly 1–1.5 GB of RAM for the daemon.

Install ClamAV and update signatures

sudo apt update
sudo apt install clamav clamav-daemon
ComponentWhat it does
clamscanStandalone scanner; loads signatures each time it runs (simple but slow to start)
clamd (clamav-daemon)Background service that keeps signatures in memory for fast scans
clamdscanClient that sends scan jobs to clamd
freshclamDownloads signature updates; runs as the clamav-freshclam service

The freshclam service updates signatures automatically. Check that it is working:

sudo systemctl status clamav-freshclam
sudo tail /var/log/clamav/freshclam.log

If you want to run freshclam by hand and it reports a lock error, stop the service first (sudo systemctl stop clamav-freshclam), run it, then start the service again. The official ClamAV documentation covers configuration in depth.

Plan for memory use

The signature database is large. When clamd loads it, expect it to use roughly 1–1.5 GB of RAM, and briefly more while reloading after an update. On a small VPS, either run occasional clamscan jobs instead of the daemon, or choose a plan with enough memory for both your applications and ClamAV.

ClamAV – SkyRain Cloud servers in India

Run your first scans

With clamscan

sudo clamscan -r -i /var/www
sudo clamscan -r -i --exclude-dir="^/sys|^/proc|^/dev" /

-r scans recursively and -i prints only infected files. Scanning web roots, upload folders, /tmp, /var/tmp and home directories gives the best return for the time. A full-system scan takes much longer.

With the daemon (faster)

sudo systemctl enable --now clamav-daemon
sudo clamdscan --multiscan --fdpass -i /var/www

--multiscan uses several threads, and --fdpass lets clamd read files it would not otherwise have permission to open.

Moving infected files instead of deleting them

sudo mkdir -p /root/quarantine
sudo clamscan -r -i --move=/root/quarantine /var/www

Quarantining keeps evidence for investigation. Avoid --remove on a live website until you know what the file is: a false positive could break the site, and a real infection needs investigating, not just deleting.

Schedule regular scans

Create /etc/cron.daily/clamav-scan:

#!/bin/sh
LOG=/var/log/clamav/daily-scan.log
clamdscan --multiscan --fdpass -i /var/www /home /tmp > "$LOG" 2>&1
if grep -q "FOUND" "$LOG"; then
  mail -s "ClamAV found malware on $(hostname)" admin@example.com < "$LOG"
fi
sudo chmod +x /etc/cron.daily/clamav-scan

The email step needs a working mail setup; replace it with a webhook or your monitoring tool if you prefer. Run the scan at a quiet hour, because scanning large sites uses CPU and disk.

What ClamAV can and cannot do

ClamAV is useful, but it is not a complete security system:

  • It finds known malware. Detection relies on signatures, so brand-new or heavily obfuscated web shells may be missed.
  • It scans files, not behaviour. A cryptominer running from memory, or an attacker using a stolen password, will not show up in a file scan.
  • It does not fix the entry point. If an outdated plugin let malware in, it will come back until the plugin is updated.

Combine it with other layers:

  • Linux Malware Detect (maldet), which focuses on web-hosting threats and can use ClamAV's engine.
  • rkhunter or chkrootkit to look for rootkits.
  • File-integrity monitoring such as AIDE, which alerts when system files change.
  • Prompt updates for the OS, CMS, plugins and themes, plus strong SSH settings; see the server hardening guide.

What to do if ClamAV finds malware

  1. Do not panic-delete. Quarantine the files and note their paths and timestamps.
  2. Check for a false positive. Look at the file. Some admin tools and minified scripts trigger heuristic signatures.
  3. Find the entry point. Compare file timestamps with web server access logs to see which request created them.
  4. Close the hole: update the vulnerable software and change every password the site or server uses, including database passwords; our guide to resetting MySQL passwords helps.
  5. Look for persistence: unknown cron jobs, new users, new SSH keys and unfamiliar processes. Our VPS troubleshooting guide lists the commands.
  6. Rebuild if in doubt. If an attacker had root access, restore onto a clean installation from a backup taken before the compromise.

Why developers choose SkyRain Cloud VPS

Security tools need resources to run well. SkyRain Cloud Intel VPS plans give you:

  • KVM virtualization. Your own kernel and allocated vCores, so you can tune the system the way this guide describes.
  • Intel Xeon Platinum 8269CY hosts. Server-class Cascade Lake CPUs with DDR4 ECC memory.
  • NVMe SSD storage on every plan, which keeps I/O wait low for databases and builds.
  • Full root access to install and configure whatever your stack needs.
  • Unmetered 1 Gbps port in India, close to your users.
  • Simple billing and real support. Monthly billing in rupees with UPI, plus 24/7 tickets, WhatsApp and Discord.

Frequently Asked Questions

Is ClamAV free?
Yes. ClamAV is open-source and free to use on Linux servers, with signature updates provided through freshclam.
How do I scan a folder with ClamAV?
Run sudo clamscan -r -i /path/to/folder. The -r option scans recursively and -i lists only infected files.
How much RAM does ClamAV need?
The clamd daemon typically uses around 1 to 1.5 GB of RAM once signatures are loaded. On small servers, run clamscan occasionally instead of keeping the daemon running.
Does ClamAV detect PHP web shells?
It detects many known ones, but new or obfuscated web shells can be missed. Use it alongside tools like Linux Malware Detect and keep your CMS and plugins updated.
How do I update ClamAV virus definitions?
The clamav-freshclam service updates them automatically. To update manually, stop the service, run sudo freshclam, then start the service again.
Should I delete infected files automatically?
It is safer to quarantine them with --move, check for false positives, and investigate how they got there before removing anything.

Conclusion

ClamAV gives you a free, scriptable way to check a Linux server for known malware. Install it, let freshclam keep signatures current, scan web roots and temporary folders on a schedule, and quarantine rather than delete. Treat it as one layer: keeping software updated and access locked down prevents most infections in the first place.

For a VPS with root access and room for security tools, see our Intel VPS plans.

SkyRain Cloud Intel Xeon VPS Plans

KVM VPS on Intel Xeon Platinum 8269CY (up to 3.80 GHz Turbo) with DDR4 ECC memory, NVMe SSD, full root access and an unmetered 1 Gbps port.

PlanvCoresRAMStorageNetworkPriceGood forBuy
VPS 1 — Intel28 GB DDR4 ECC40 GB NVMe SSD1 Gbps, unmetered₹649/monthBusiness websites, small apps, scheduled jobs and botsOrder
VPS 2 — Intel416 GB DDR4 ECC80 GB NVMe SSD1 Gbps, unmetered₹1,169/monthBusiness software, mid-size databases, several sites on one serverCheck stock
VPS 3 — Intel832 GB DDR4 ECC150 GB NVMe SSD1 Gbps, unmetered₹2,249/monthERP/CRM stacks, heavier databases, multiple production appsCheck stock
VPS 4 — Intel1664 GB DDR4 ECC250 GB NVMe SSD1 Gbps, unmetered₹4,299/monthHigh-memory workloads and consolidated production serversCheck stock

Prices are monthly in INR as listed on the SkyRain Cloud store (verified 2026-11-23). Live stock and final price are shown at checkout.

Instant UPI • ₹649/mo
Fast KVM Cloud Provisioning