Techridez
VirtualizationLinuxWindowsNetworking
  • Techridez Knowledge base
  • Techridez guide
  • Tech Scale
    • Measurements
  • Techridez Knowledge Base
  • Bacis
    • Protocol and Port Numbers
  • Windows Customization
    • Capture Wim image from OS
  • Virtualization
    • Proxmox Command Guide
  • Windows Server Guide
    • Transfer FSMO roles
    • FSMO commands
  • DevOps
    • WebDev
      • How to install fail2ban on ubuntu server and create custom jail config.
      • MySQL Bin Files Eating Lots of Disk Space (fix)
      • Install ClamAV antivirus in Ubuntu Server and Client With Cron job
      • 404 hyperlink not working after wordpress migration
      • Apache Virtual Host Script with mysql db.
      • OsTicket
      • How to Backup MySQL Databases Automatically on Ubuntu
      • Cron Job
        • Create cron job for maldet scanning
        • Auto-Restart MySQL When It Crashes During a Brute Force Attack
        • How to change default crontab editor
        • How To Use Cron to Automate Tasks on Ubuntu 18.04
        • How To Use Cron to Automate Tasks on CentOS 8
      • Wordpress Security
      • Open database Error!: could not find driver linux Fix
    • Vagrant
    • Windows Subsystem for Linux
    • How to set static ip on ubuntu server using yaml file.
    • How to install ansible
  • Linux
    • Tools
    • How to install CrowdStrike in Linux
    • How to Install Ossec agent in linux
    • Linux Commands
    • SFTP (CrushFTP)with HA
    • 🗃️Transfer & sync files in a directory to remote node using crontab & rsync
  • Networking
    • Upgrade Cisco9200L firmware to recommended
  • Cyber Security
    • ISC² (International Information System Security Certification Consortium)
Powered by GitBook

©️ Techridez

On this page

Was this helpful?

  1. DevOps
  2. WebDev

Install ClamAV antivirus in Ubuntu Server and Client With Cron job

In this how to we will install ClamAV 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

sudo apt-get install clamav clamtk

This will install ClamAV and the GUI frontend ClamTK. 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:

sudo apt-get install clamav clamav-daemon

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

sudo dpkg-reconfigure clamav-base
sudo freshclam
sudo /etc/init.d/clamav-daemon start

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

#!/bin/sh
 
# emtpy the old scanlog and do a virus scan
rm -R /home/root/clamav/clamav-scan.log
touch /home/root/clamav/clamav-scan.log
clamdscan /home/ /etc/ /opt/ --fdpass --log=/home/root/clamav/clamav-scan.log --infected --multiscan
 
### Send the email
if grep -rl 'Infected files: 0' /home/root/clamav/clamav-scan.log
then echo "No virus found inside /home."
else cat /home/root/clamav/clamav-scan.log | mail -s "Virus warning inside folder /home" root
fi

Next we need to make the file executable with the following command:

Make the clamav-scan.sh executablesudo

chmod +x clamav-scan.sh

After that we add this file as a cronjob which executes every night at 3am:

Add the cronjob for the scan

sudo crontab -e

# enter the following line 00 03 * * * {PATH-TO-SCRIPT}/clamav-scan.sh

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

X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*

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 https://guylabs.ch/2013/09/18/install-clamav-antivirus-in-ubuntu-server-and-client/

PreviousMySQL Bin Files Eating Lots of Disk Space (fix)Next404 hyperlink not working after wordpress migration

Last updated 4 years ago

Was this helpful?