Skip to content

ClamAV and freshclam — antivirus on Linux servers

Installing ClamAV for on-demand and on-access scanning, keeping signatures fresh with freshclam, and where ClamAV genuinely earns its CPU budget on a server.

ClamAV is the open-source antivirus engine that ships in every distro repo. On a Linux server, “antivirus” is rarely about stopping a Linux malware infection of the host; it is about scanning files that pass through the host — mail attachments, uploaded user files, shared storage — so a Windows or macOS endpoint downstream is not the one that gets ambushed. This article covers the install, the signature update flow, and the integration points where ClamAV is actually useful.

How to verify

Check the install, the signature freshness, and a quick scan:

sudo systemctl status clamav-daemon clamav-freshclam
sudo freshclam --version
sudo cat /var/log/clamav/freshclam.log | tail -5
sudo clamdscan --version
sudo echo 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > /tmp/eicar.txt
sudo clamdscan /tmp/eicar.txt

The EICAR string is the standardised antivirus test signature — every working AV will flag it. The freshclam log tells you when the signatures last updated.

What’s happening

ClamAV has three components. clamd is the resident scanning daemon — load signatures once, scan many files. freshclam is the signature updater — pulls new daily signature bundles from the ClamAV mirrors. clamscan is the standalone scanner — loads signatures fresh on each invocation (slow). For production, you almost always want clamdscan (talks to the daemon) or clamonacc (on-access scanner using fanotify).

Signatures are huge — the daily.cvd file is in the hundreds of megabytes — and updated multiple times a day. freshclam handles incremental updates, but the first sync on a fresh host pulls everything and can take minutes. The official mirrors are rate-limited; large fleets should run a local CVDUpdate mirror to avoid throttling.

ClamAV on a busy Linux server costs CPU and memory: a clamd with the full signature set resident takes 1–2 GB of RAM. The right places to spend that budget are SMTP gateways (clamsmtp / amavisd-new), file upload paths in web apps (ICAP via c-icap), and shared storage that Windows clients write to.

The procedure

  1. Install. sudo apt install clamav clamav-daemon clamav-freshclam (Debian/Ubuntu) or sudo dnf install clamav clamd clamav-update (RHEL family). On RHEL, also sudo setsebool -P antivirus_can_scan_system 1 so clamd can read everywhere it needs to.
  2. Bootstrap signatures. sudo systemctl stop clamav-freshclam && sudo freshclam && sudo systemctl start clamav-freshclam. Stopping the service is required because the systemd unit also runs freshclam and the two will collide on the first run.
  3. Start the daemon. sudo systemctl enable --now clamav-daemon. The first start can take several minutes while it loads the signature database into memory — watch journalctl -u clamav-daemon -f.
  4. Tune /etc/clamav/clamd.conf. MaxFileSize 100M, MaxScanSize 400M, MaxRecursion 16, MaxFiles 10000 — the defaults are low and reject larger attachments. Increase to match your actual file sizes. DetectPUA yes enables potentially unwanted application detection.
  5. Tune /etc/clamav/freshclam.conf. DatabaseMirror db.local.clamav.net to use a regional mirror, Checks 24 for 24 update checks per day (every hour). For air-gapped hosts, point DatabaseMirror at your internal CVDUpdate proxy.
  6. Set up scheduled scanning of paths that matter. A nightly cron: clamdscan --multiscan --fdpass --quiet --infected /srv/uploads /var/www | mail -s "ClamAV $(hostname) $(date)" sec@example.com. --fdpass lets clamd open files even when running as a different user.
  7. Enable on-access scanning where it earns its place. clamonacc watches paths via fanotify and blocks open() on infected files. Configure with OnAccessIncludePath /srv/uploads in clamd.conf. The latency overhead is real; reserve it for paths that need synchronous protection.
  8. Forward detections to your monitoring. clamd writes findings to /var/log/clamav/clamav.log. Ship via promtail/syslog and alert on FOUND lines — a quiet log is the goal; the next finding is the one that matters.

Common pitfalls

  • The freshclam daemon refuses to update if /var/log/clamav/freshclam.log is owned by anyone but the clamav user — file permissions reset across package upgrades occasionally. sudo chown clamav:clamav /var/log/clamav/* fixes the most common case.
  • ClamAV’s detection rate against modern threats is lower than commercial AV. It is excellent at known signatures and weak on heuristics. Pair with YARA rules for custom patterns and a SIEM for behavioural signal.
  • The default MaxScanSize of 100 MB rejects most modern attachments — a 200 MB ISO will scan as “clean” (it skipped the scan) without obvious warning. Always tune the size limits.
  • clamonacc requires the kernel to be built with fanotify, the fanotify_can_mark capability, and (on some kernels) kernel.dmesg_restrict not blocking the open notifications. Verify on the target kernel.
  • A signature update with corrupted data can cause clamd to refuse to load. freshclam keeps the previous signature DB; manual recovery is sudo cp /var/lib/clamav/daily.cvd.old /var/lib/clamav/daily.cvd && sudo systemctl restart clamav-daemon.

In the engagements we run, ClamAV is one component of a layered file safety story — quarantine on detection, alert on repeat detections, audit on signature update failures. That layered model fits inside Managed Operations — an antivirus that no one watches is the most expensive way to feel safe.