Install ClamAV antivirus in Ubuntu Server and Client With Cron job
Last updated
Was this helpful?
Last updated
Was this helpful?
In this how to we will install antivirus on an Ubuntu client and a server. First we will install it on the client with the following command:Install clamav packagesudo apt-get install clamav clamtk
This will install ClamAV and the GUI frontend . You can configure daily scans and virus definition updates inside this tool.
To install ClamAV on an Ubuntu server we start by installing ClamAV and the daemon by executing the following commands:
Next we need to reconfigure the ClamAV base package, update the virus definitions and start the daemon. Execute the following commands
Reconfigure ClamAV and update virus definitions
#set the maximum directory recursion to 50 such that all directories are getting scanned
# set to follow directory sym links to true
Next we need to create a shell script which scans a specific directory and sends an email if a virus is found. Place that shell script inside the user home of the root user or somewhere else. I placed it inside /home/clamav. Ok now create a file with the command ‘sudo vi clamav-scan.sh’ and enter the following content:
clamav-scan.sh#!/bin/sh
Next we need to make the file executable with the following command:
Make the clamav-scan.sh executablesudo
After that we add this file as a cronjob which executes every night at 3am:
Add the cronjob for the scan
Substitute the {PATH-TO-SCRIPT} placeholder with the path where the clamav-scan.sh script is stored.
Next we infect the folder you want to scan with the EICAR test virus. For that create a text file and add the following content to it:
EICAR test virus
Store it and then run the created clamav-scan.sh to see if the virus is found and the mail is sent. After everything worked as it should, delete the test virus text file.
But be aware: The clamav-scan.sh script identifies the viruses and doesn’t delete them, that has to be done manually.
Source