DebianDebian BasedTutorials

How To Install ClamAV Antivirus on Debian 11

Install ClamAV Antivirus on Debian 11

In this tutorial, we will show you how to install ClamAV Antivirus on Debian 11. For those of you who didn’t know, ClamAV is an open-source antivirus engine for detecting trojans, viruses, malware & other malicious threats. It integrates Mail servers to scan attachments received. In addition to scanning mail attachments, it provides protection to corporate networks. ClamAV package provides a flexible and scalable multi-threaded daemon in the clamav-daemon package, a command-line scanner in the ClamAV package, and a tool for automatic updating via the Internet.

This article assumes you have at least basic knowledge of Linux, know how to use the shell, and most importantly, you host your site on your own VPS. The installation is quite simple and assumes you are running in the root account, if not you may need to add ‘sudo‘ to the commands to get root privileges. I will show you the step-by-step installation of the ClamAV on a Debian 11 (Bullseye).

Prerequisites

  • A server running one of the following operating systems: Debian 10 or Debian 11.
  • It’s recommended that you use a fresh OS install to prevent any potential issues.
  • SSH access to the server (or just open Terminal if you’re on a desktop).
  • A non-root sudo user or access to the root user. We recommend acting as a non-root sudo user, however, as you can harm your system if you’re not careful when acting as the root.

Install ClamAV Antivirus on Debian 11 Bullseye

Step 1. Before we install any software, it’s important to make sure your system is up to date by running the following apt commands in the terminal:

sudo apt update
sudo apt upgrade

Step 3. Installing ClamAV Antivirus on Debian 11.

By default, ClamAV is available on Debian 11 base repository. So, now run the following command below to install the ClamAV Antivirus packages on your Debian system:

sudo apt install clamav clamav-daemon

You can verify your ClamAV installation and also check the version:

clamscan --version

Step 3. Update the ClamAV Signature Database.

Once the installation is complete, you’ll need to stop the daemon, so you can update the ClamAV database manually. Stop the daemon with the command below:

sudo systemctl stop clamav-freshclam

Next, we update the database ClamAV from the internet with the command:

sudo freshclam

After that, start the freshclam daemon with the command:

sudo systemctl start clamav-freshclam

Step 4. Set Up ClamAV to Scan Automatically.

Now we create the script with the command below:

nano /usr/local/bin/clamscan_daily.sh

Add the following file:

#!/bin/bash
LOGFILE="/var/log/clamav/clamav-$(date +'%Y-%m-%d').log";
EMAIL_MSG="Please see the log file attached";
EMAIL_FROM="admin@your-domain.com";
EMAIL_TO="user@your-domain.com";
DIRTOSCAN="/var/www/html";
 

for S in ${DIRTOSCAN}; do
 DIRSIZE=$(du -sh "$S" 2>/dev/null | cut -f1);
 echo "Starting scan of "$S" directory.
 Directory size: "$DIRSIZE".";
 clamscan -ri --remove --detect-pua=yes "$S" >> "$LOGFILE";
 #find /var/log/clamav/ -type f -mtime +30 -exec rm {} \;
 MALWARE=$(tail "$LOGFILE"|grep Infected|cut -d" " -f3);

  if [ "$MALWARE" -ne "0" ];then
     echo "$EMAIL_MSG"|mail -a "$LOGFILE" -s "Malware Found" -r "$EMAIL_FROM" "$EMAIL_TO";
  fi

done

exit 0

Save and close the file, then give executable permissions:

sudo chmod u+x /usr/local/bin/clamscan_daily.sh

Next, create the cron job with the command:

sudo crontab -e

Add the following line to run the scan every day at 1 am:

1 1 * * * /usrlocal/bin/clamscan_daily.sh > /dev/null 2>&1

At this point, ClamAV will automatically scan the /var/www/html directory for malicious files and alert you if it finds anything.

The ClamAV utility provides you with many options on the basis of which you can scan files and folders on your system for viruses. You can get detail about these options by viewing the ClamAV help as follows:

clamscan --help

Congratulations! You have successfully installed ClamAV. Thanks for using this tutorial for installing the latest version of the ClamAV Antivirus on Debian 11 Bullseye. For additional help or useful information, we recommend you check the official ClamAV website.

VPS Manage Service Offer
If you don’t have time to do all of this stuff, or if this is not your area of expertise, we offer a service to do “VPS Manage Service Offer”, starting from $10 (Paypal payment). Please contact us to get the best deal!

r00t

r00t is an experienced Linux enthusiast and technical writer with a passion for open-source software. With years of hands-on experience in various Linux distributions, r00t has developed a deep understanding of the Linux ecosystem and its powerful tools. He holds certifications in SCE and has contributed to several open-source projects. r00t is dedicated to sharing her knowledge and expertise through well-researched and informative articles, helping others navigate the world of Linux with confidence.
Back to top button