How to Install and Use ClamAV Antivirus

Installing and Using ClamAV Antivirus

ClamAV is a free, open-source antivirus engine for Linux. While Linux malware is less common than on Windows, scanning is good practice — especially for servers that handle user-uploaded files.

Install ClamAV

apt update
apt install clamav clamav-daemon -y

Update Virus Definitions

# Stop the daemon first:
systemctl stop clamav-freshclam
# Update manually:
freshclam
# Restart:
systemctl start clamav-freshclam

Run a Manual Scan

# Scan a directory:
clamscan -r /var/www/html

# Scan and only show infected files:
clamscan -r --infected /home

# Scan and move infected files to quarantine:
clamscan -r --infected --move=/quarantine /uploads

Schedule Regular Scans

crontab -e
# Scan uploads directory every day at 2 AM:
0 2 * * * clamscan -r --infected /var/www/uploads >> /var/log/clamav_scan.log 2>&1

Enable the ClamAV Daemon for On-Access Scanning

systemctl enable clamav-daemon
systemctl start clamav-daemon

The daemon (clamd) loads virus definitions into memory for faster scanning and can be used by web applications to scan file uploads in real time.

Interpreting Results

  • OK — file is clean
  • FOUND — infection detected — quarantine or delete the file immediately
  • ERROR — file could not be read (usually a permissions issue)
  • 0 gebruikers vonden dit artikel nuttig
Was dit antwoord nuttig?

Gerelateerde artikelen

Securing SSH Access

Securing SSH Access SSH is the main entry point to your server. Hardening it is one of the most...

Setting Up a Firewall with UFW

Setting Up a Firewall with UFW UFW (Uncomplicated Firewall) makes managing firewall rules...

Installing Fail2Ban to Prevent Brute Force Attacks

Installing Fail2Ban Fail2Ban monitors your log files and automatically bans IP addresses that...

Setting Up Let's Encrypt SSL Certificates

Setting Up Let's Encrypt SSL Certificates Let's Encrypt provides free, trusted SSL certificates....

Scanning for Rootkits with rkhunter and chkrootkit

Scanning for Rootkits Rootkits are malware that hide from standard detection tools. Two widely...