Post

πŸ›‘οΈ How to Install and Use ClamAV on Ubuntu

πŸ›‘οΈ How to Install and Use ClamAV on Ubuntu

πŸ“ Installing and Use ClamAV to Scan Ubuntu for Malware

Keeping your Ubuntu system clean from malicious files is critical β€” even on Linux. In this guide, you’ll learn how to install, configure, and use ClamAV, a popular open-source antivirus tool, to scan for malware.


πŸ“¦ Step 1: Install ClamAV

First, update your system and install ClamAV:

1
sudo apt update && sudo apt install clamav clamav-daemon -y

This installs the command-line scanner and the background daemon for automatic updates.


πŸ”„ Step 2: Update Virus Definitions

ClamAV uses a virus database that must be kept up to date.

Stop the ClamAV daemon temporarily:

1
sudo systemctl stop clamav-freshclam

Manually update the definitions:

1
sudo freshclam

Then restart the daemon:

1
sudo systemctl start clamav-freshclam

πŸ’‘ Tip: The daemon will now auto-update definitions in the background.


πŸ§ͺ Step 3: Run a Manual Scan

To scan your home directory:

1
clamscan -r /home/yourusername

To scan your entire system:

1
sudo clamscan -r /

Use --bell -i to highlight infected files only:

1
sudo clamscan -r --bell -i /

βš™οΈ Step 4: Automate with Cron

You can run ClamAV daily or weekly using a cron job.

Open your crontab with the nano editor:

1
crontab -e

πŸ“ If it’s your first time using crontab, it may ask you to select an editor. Choose nano if available (usually option 1).

Add this line to schedule a scan every night at 2 AM:

0 2 * * * clamscan -r /home/yourusername --bell -i >> /var/log/clamav/scan.log

In nano, press Ctrl+O to save, then Enter, and Ctrl+X to exit.


πŸ“ Optional: Use clamdscan for Faster Scans

clamdscan uses the daemon to scan faster than clamscan:

1
sudo clamdscan -r /home/yourusername

Make sure the ClamAV daemon is running:

1
sudo systemctl status clamav-daemon

βœ… You’re Protected

ClamAV isn’t just for servers β€” it’s also a smart choice for Linux desktops, file gateways, and anything that touches shared files. Stay secure, scan regularly, and automate where possible. ☁️🐧

This post is licensed under CC BY 4.0 by the author.