π‘οΈ 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. Choosenanoif 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. βοΈπ§
