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
- Install.
sudo apt install clamav clamav-daemon clamav-freshclam(Debian/Ubuntu) orsudo dnf install clamav clamd clamav-update(RHEL family). On RHEL, alsosudo setsebool -P antivirus_can_scan_system 1so clamd can read everywhere it needs to. - 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. - Start the daemon.
sudo systemctl enable --now clamav-daemon. The first start can take several minutes while it loads the signature database into memory — watchjournalctl -u clamav-daemon -f. - 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 yesenables potentially unwanted application detection. - Tune
/etc/clamav/freshclam.conf.DatabaseMirror db.local.clamav.netto use a regional mirror,Checks 24for 24 update checks per day (every hour). For air-gapped hosts, pointDatabaseMirrorat your internal CVDUpdate proxy. - 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.--fdpasslets clamd open files even when running as a different user. - Enable on-access scanning where it earns its place.
clamonaccwatches paths via fanotify and blocks open() on infected files. Configure withOnAccessIncludePath /srv/uploadsin clamd.conf. The latency overhead is real; reserve it for paths that need synchronous protection. - Forward detections to your monitoring. clamd writes findings to
/var/log/clamav/clamav.log. Ship via promtail/syslog and alert onFOUNDlines — 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.logis 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
MaxScanSizeof 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. clamonaccrequires the kernel to be built with fanotify, thefanotify_can_markcapability, and (on some kernels)kernel.dmesg_restrictnot 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.