To fix ClamAV on a Linux server, update packages, refresh the virus database with FreshClam, repair permissions, and restart clamd. Common steps include clearing corrupted databases, fixing mirror/proxy settings, resolving SELinux/AppArmor denials, and checking systemd logs.
The guide below provides quick fixes and deep troubleshooting for Ubuntu, Debian, CentOS, AlmaLinux, and Rocky Linux.
If you’re wondering how to fix ClamAV on Linux server instances, you’re likely facing FreshClam update failures, clamd startup errors, database corruption, or slow scans causing timeouts. As a Linux hosting provider, we see these issues often. This beginner-friendly, expert-written guide walks you through fast fixes and comprehensive troubleshooting on popular distributions.
What ClamAV Does (and Why It Breaks)
ClamAV has three moving parts:
- freshclam: Updates the virus signature database (main.cvd, daily.cvd, bytecode.cvd).
- clamd: The always-on daemon that scans quickly via a socket.
- clamscan/clamdscan: Run manual or scripted scans.
Things break when mirrors are unreachable, DNS/proxies block updates, databases corrupt, or system security frameworks (SELinux/AppArmor) restrict access. Misconfigurations in clamd.conf or freshclam.conf also cause failures.
Common ClamAV Errors on Linux
- freshclam: “Can’t query
database.clamav.net” or “Connection timed out” - freshclam: “Mirror not synchronized” or “Update failed”
- clamd: “Can’t open/parse
main.cvd/daily.cvd” - clamd: “Socket permission denied” or “Can’t open
/var/run/clamav/clamd.ctl” - Systemd: “Failed to start clamd@scan.service” or “Exit code=exited, status=1/FAILURE”
- Slow or stuck scans, heavy I/O causing timeouts
Quick Fix Checklist (Solves Most Cases)
- Ensure updates and EPEL (RHEL family) are enabled.
- Clear corrupted AV databases and force a full refresh.
- Fix permissions/ownership for ClamAV directories and sockets.
- Check SELinux/AppArmor denials and allow required paths.
- Restart clamd and freshclam; review logs with journalctl.
# 1) Update OS + ClamAV packages
# Debian/Ubuntu
sudo apt update && sudo apt install --reinstall clamav clamav-daemon -y
# RHEL/CentOS/Alma/Rocky
sudo dnf install -y epel-release && sudo dnf install -y clamav clamav-update clamd
# 2) Stop services
sudo systemctl stop clamav-freshclam || true
sudo systemctl stop clamd@scan clamd || true
# 3) Clear corrupt databases and refresh
sudo rm -f /var/lib/clamav/*.cvd /var/lib/clamav/*.cld
sudo freshclam
# 4) Fix permissions (user/group names may be clamav)
sudo chown -R clamav:clamav /var/lib/clamav /var/run/clamav /var/log/clamav
sudo chmod 750 /var/lib/clamav
# 5) Start services and check status
sudo systemctl enable --now clamav-freshclam || true
sudo systemctl enable --now clamd@scan clamd || true
sudo systemctl status clamav-freshclam clamd@scan clamd --no-pager
journalctl -u clamd@scan -u clamd -u clamav-freshclam -b --no-pager
Step-by-Step Fixes (Root Cause Oriented)
1) Update Packages and Reinstall ClamAV Cleanly
Out-of-date packages or mismatched components often break FreshClam or clamd. Reinstalling ensures binaries and systemd units match.
# Debian/Ubuntu
sudo apt update
sudo apt install --reinstall clamav clamav-daemon -y
# RHEL/CentOS/Alma/Rocky
sudo dnf install -y epel-release
sudo dnf install -y clamav clamav-update clamd
2) Fix FreshClam Update Failures (DNS, Proxy, Mirrors)
If freshclam can’t reach database.clamav.net, check DNS, firewall, and proxies. FreshClam uses HTTPS; allow outbound 80/443 and verify the server’s resolver works.
# Test connectivity and DNS
ping -c2 database.clamav.net || true
dig database.clamav.net +short
curl -I https://database.clamav.net/
Behind a proxy, set it in /etc/clamav/freshclam.conf (Debian/Ubuntu) or /etc/freshclam.conf (RHEL):
HTTPProxyServer your.proxy.local
HTTPProxyPort 3128
# Optional auth
# HTTPProxyUsername user
# HTTPProxyPassword pass
If a mirror is stale, comment custom mirrors and let FreshClam auto-select:
# Comment out any custom mirror lines:
# DatabaseMirror your.custom.mirror
# Ensure these are present:
DatabaseMirror database.clamav.net
DNSDatabaseInfo current.cvd.clamav.net
3) Repair clamd Startup: Sockets, Paths, and Systemd Units
clamd must load databases and create a socket. Validate paths in clamd.conf (Ubuntu: /etc/clamav/clamd.conf, RHEL: /etc/clamd.d/scan.conf for clamd@scan).
# Key settings to verify
User clamav
LocalSocket /var/run/clamav/clamd.ctl
LocalSocketMode 666
LogFile /var/log/clamav/clamd.log
DatabaseDirectory /var/lib/clamav
Ensure directories exist and are owned by the clamd user:
sudo mkdir -p /var/run/clamav /var/log/clamav
sudo chown -R clamav:clamav /var/run/clamav /var/log/clamav /var/lib/clamav
sudo systemctl restart clamd@scan clamd
journalctl -u clamd@scan -u clamd -b --no-pager
4) Resolve SELinux/AppArmor Denials
Security frameworks may block clamd from its socket or databases. Check logs for denials and permit access.
# SELinux
sestatus
sudo ausearch -m avc -ts recent | audit2why
# Temporarily permissive (test only)
sudo setenforce 0
# Generate allow policy if needed
sudo ausearch -m avc -ts recent | audit2allow -M clamav_local
sudo semodule -i clamav_local.pp
# AppArmor (Ubuntu)
sudo aa-status
sudo journalctl -k | grep DENIED -i
# Put clamd in complain mode (test only)
sudo aa-complain /etc/apparmor.d/usr.sbin.clamd
5) Rebuild a Corrupted Database
Corrupt signatures make clamd fail to start. Rebuild safely:
sudo systemctl stop clamd@scan clamd clamav-freshclam
sudo rm -f /var/lib/clamav/*.cvd /var/lib/clamav/*.cld
sudo freshclam
sudo systemctl start clamav-freshclam
sudo systemctl start clamd@scan clamd
6) Network, Time, and Rate-Limit Issues
Incorrect time skews TLS and DNS. Also avoid aggressive update loops that trigger rate limits.
- Ensure NTP/time sync is correct (chrony/systemd-timesyncd).
- Run FreshClam via systemd; avoid cron loops less than 1 hour.
- Throttle retries with
ConnectTimeoutandReceiveTimeoutin freshclam.conf if needed.
7) Performance Tuning to Prevent Timeouts
Large directories, archives, or email queues can slow scans. Tune clamd to balance accuracy and speed.
# In clamd.conf (values depend on server size)
MaxScanSize 1G
MaxFileSize 200M
MaxRecursion 16
MaxThreads 8
LogTime yes
# Exclude hot paths or volatile caches via OnAccessExcludePath (if using on-access)
Use clamdscan (daemon-based) instead of clamscan for better performance on repeated scans.
How to Run and Schedule Malware Scans
On-Demand Scans
# Quick scan of /home with summary
clamscan -ri /home --bell -l /var/log/clamav/manual-scan.log
# Faster via daemon
clamdscan --fdpass -ri /home
Exclusions and False Positives
- Exclude backups, caches, or VM images to cut noise and I/O.
- Use
--excludeand--exclude-diror OnAccessExcludePath. - Quarantine suspicious files rather than auto-delete in production.
clamscan -ri / --exclude-dir="^/proc" --exclude-dir="^/sys" --exclude-dir="^/dev" \
--exclude-dir="^/var/lib/docker" --exclude="\.iso$" --exclude="\.img$"
Scheduling with Cron or systemd
# Cron example: nightly scan
sudo bash -c 'cat >/etc/cron.d/clamav-scan' <<EOF
0 2 * * * root clamdscan --fdpass -ri /home >>/var/log/clamav/nightly.log 2>>&1
EOF
# systemd timer (preferred for reliability)
sudo bash -c 'cat >/etc/systemd/system/clamav-scan.service' <<EOF
[Unit]
Description=Nightly ClamAV scan
[Service]
Type=oneshot
ExecStart=/usr/bin/clamdscan --fdpass -ri /home
EOF
sudo bash -c 'cat >/etc/systemd/system/clamav-scan.timer' <<EOF
[Unit]
Description=Run ClamAV scan nightly
[Timer]
OnCalendar=02:00
Persistent=true
[Install]
WantedBy=timers.target
EOF
sudo systemctl daemon-reload
sudo systemctl enable --now clamav-scan.timer
systemctl list-timers --all | grep clamav
Hardening and Best Practices
- Keep OS and ClamAV updated; automate FreshClam via systemd.
- Log to files and centralize with journald/syslog for auditing.
- Enable SELinux/AppArmor with proper policies in production.
- Use clamd for speed; tune MaxScanSize/MaxThreads on bigger servers.
- Integrate with mail servers (Postfix/Exim) or file upload pipelines.
Troubleshooting Cheat Sheet
# Service status and logs
systemctl status clamd@scan clamd clamav-freshclam --no-pager
journalctl -u clamd@scan -u clamd -u clamav-freshclam -b --no-pager
# Verify signatures
ls -lh /var/lib/clamav/
sigtool --info /var/lib/clamav/daily.cvd
# Test scan and connectivity
clamscan --version
freshclam -v
# Restore defaults (Debian/Ubuntu)
sudo dpkg-reconfigure clamav-freshclam
When to Reinstall or Build from Source
- Reinstall if packages or configs are inconsistent after upgrades.
- Build from source when you need the latest engine or features not yet in your distro, and you’re comfortable maintaining it.
- Always back up configs (
freshclam.conf,clamd.conf) before changes.
ClamAV on cPanel, Plesk, and Hosting Panels
On cPanel/WHM or Plesk, use the panel’s package installer and GUI to manage updates and scans. If FreshClam or clamd fail through the panel, fix them at the OS level first (as above), then resync via the panel. Always check panel-specific service names and paths.
Why Managed Hosting Helps
Security tools break at the worst time. With a managed VPS or dedicated server at YouStable, our engineers monitor FreshClam, tune clamd for your workload, harden SELinux/AppArmor, and integrate alerts. That saves hours of guesswork and keeps your server clean and compliant without slowing your apps.
FAQs
How do I fix “freshclam update failed” on Ubuntu or Debian?
Reinstall packages, clear databases, and run FreshClam manually. Check DNS/proxy and ensure outbound 80/443 is open. In /etc/clamav/freshclam.conf, use the default mirror (database.clamav.net) and remove custom mirrors. Finally, restart services and review journalctl -u clamav-freshclam.
Why does clamd fail to start after an update?
Typical causes are corrupted databases, wrong DatabaseDirectory, missing socket/log directories, or SELinux/AppArmor denials. Rebuild the database, verify clamd.conf paths, fix ownership to the clamav user, and check systemd logs for the exact error string.
How can I force a full ClamAV database refresh?
Stop clamd and FreshClam, delete /var/lib/clamav/*.cvd and *.cld, then run freshclam. Start services afterward. This clears corruption and downloads the latest main, daily, and bytecode databases.
How do I speed up ClamAV on production servers?
Use clamdscan, tune MaxScanSize, MaxFileSize, and MaxThreads, and exclude heavy paths (caches, images, backups). Schedule scans during off-peak hours and keep signature updates regular to reduce first-scan overhead.
Is ClamAV enough to secure a Linux server?
No. ClamAV detects known malware but doesn’t replace patch management, firewalls, WAF, kernel hardening, least-privilege access, and backups. Use ClamAV as part of a layered defense strategy. Managed providers like YouStable bundle these controls for comprehensive protection.