Windows OS Hub
  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu
  • Home
  • About

Windows OS Hub

  • Windows Server
    • Windows Server 2022
    • Windows Server 2019
    • Windows Server 2016
    • Windows Server 2012 R2
    • Windows Server 2008 R2
    • SCCM
  • Active Directory
    • Active Directory Domain Services (AD DS)
    • Group Policies
  • Windows Clients
    • Windows 11
    • Windows 10
    • Windows 8
    • Windows 7
    • Windows XP
    • MS Office
    • Outlook
  • Virtualization
    • VMWare
    • Hyper-V
    • KVM
  • PowerShell
  • Exchange
  • Cloud
    • Azure
    • Microsoft 365
    • Office 365
  • Linux
    • CentOS
    • RHEL
    • Ubuntu

 Windows OS Hub / Linux / How to Install and Use ClamAV Antivirus on CentOS/RHEL?

May 10, 2023 CentOSLinuxQuestions and AnswersRHEL

How to Install and Use ClamAV Antivirus on CentOS/RHEL?

ClamAV is an open-source antivirus. It is used to detect viruses, trojans, and malware. It is mostly used on Linux platforms to scan user directories accessible over FTP or Samba, website directories, or emails on mail servers (as an MTA agent).

In this article, we will show how to install, configure and use the ClamAV on a host running a CentOS or RHEL Linux distros.

Contents:
  • Installing ClamAV on CentOS/RHEL
  • Basic Configuration of ClamAV in Linux
  • How to Scan for Viruses with ClamAV?

Installing ClamAV on CentOS/RHEL

ClamAV is not available in basic Linux repos, so you need to use the EPEL repository to install it on your host:

# yum install epel-release -y

After you have installed the repository, you can proceed with the installation of ClamAV packages. To install it, the yum package manager is used (or dnf on CentOS 8):

# yum -y install clamav-server clamav-data clamav-update clamav-filesystem clamav clamav-scanner-systemd clamav-devel clamav-lib clamav-server-systemd

install clamav rpm in linux

Basic Configuration of ClamAV in Linux

To set up your own ClamAV configuration, delete the default configuration in the /etc/clam.d/scan.conf.

# sed -i -e "s/^Example/#Example/" /etc/clamd.d/scan.conf

Then open the configuration file:

# nano /etc/clamd.d/scan.conf

And uncomment the following line:

LocalSocket /run/clamd.scan/clamd.sock

You can also uncomment the lines with the settings you need. For example, you can enable logging or configure the maximum number of connections.

The /etc/clamd.d/scan.conf file contains quite a detailed description of all settings.

To update the anti-virus signature databases for ClamAV, you need to use the freshclam. Backup your current configuration file:

# cp /etc/freshclam.conf /etc/freshclam.conf.bak

Then run this command:

# sed -i -e "s/^Example/#Example/" /etc/freshclam.conf

And update your antivirus definitions:

# freshclam

freshclam - update clavam antivirus definitions database

During the update, you may see some errors if you cannot download any updates. Freshclam will automatically find a mirror to download the updates successfully.

To make freshclam automatically check for updates, you may run it with -d parameter:

# freshclam -d — thus, it will check for updates every 2 hours.

freshclam: update virus databases on schedule

To run it easier, create a service file for freshclam:

# nano /usr/lib/systemd/system/freshclam.service

And add the following contents to it:

[Unit]
Description = freshclam
After = network.target
[Service]
Type = forking
ExecStart = /usr/bin/freshclam -d -c 4
Restart = on-failure
PrivateTmp = true
RestartSec = 10sec
[Install]
WantedBy=multi-user.target

Reload the systemd daemon:

# systemctl daemon-reload

Then you can start your service and add it to startup:

# systemctl start freshclam.service
# systemctl enable freshclam.service
# systemctl status freshclam.service

freshclam.service service in linux

Like you did for freshclam, create a service for ClamAV. The configuration file already exists, but you will have to change its name:

# mv /usr/lib/systemd/system/clamd\@.service /usr/lib/systemd/system/clamd.service

To make it more convenient, we have deleted \@.

Also, change the configuration in the file:

[Unit]
Description = clamd scanner daemon
After = syslog.target nss-lookup.target network.target
[Service]
Type = forking
ExecStart = /usr/sbin/clamd -c /etc/clamd.d/scan.conf
# Reload the database
ExecReload=/bin/kill -USR2 $MAINPID
Restart = on-failure
TimeoutStartSec=420
[Install]
WantedBy = multi-user.target

Then you can run the antivirus service or enable it:

# systemctl start clamd.service
# systemctl enable clamd.service

create clamd.service in linux centos/rhel

How to Scan for Viruses with ClamAV?

After you have configured the ClamAV antivirus service, you can scan any server directory for viruses (scanner mode). To scan the specified directory for viruses, use the following command:

# clamscan --infected --remove --recursive /var/www/

clamscan - How to scan for viruses with ClamAV?

With these parameters, the antivirus will immediately delete the infected files. If you want to move suspicious files to a separate directory, run the scan using the —move parameter:

# clamscan --infected --recursive --move=/tmp/clamscan /var/www

This command will scan all contents of the specified directory and move suspicious files to /tmp/clamscan.

clamav - scan summary report

As we can see, the infected file has been moved to the specified directory:

quarantine directory

You can also add the —log=/var/log/clamscan.log parameter to write all information about the scanning process in the log file you have specified:

clamscan.log

If you want to exclude some of the directories from scanning, use the —exclude-dir parameter:

# clamscan -i --recursive --move=/tmp/clamscan --log=/var/log/clamscan.log --exclude-dir="/var/www/administrator" /var/www

To scan for viruses regularly, you can configure a cron job with the settings you want.

There is a graphical frontend for the ClamAV antivirus called ClamTk.

1 comment
0
Facebook Twitter Google + Pinterest
previous post
How to Check Office 2019, 2016 and 365 License Activation Status?
next post
Find the Current User Logged on a Remote Computer

Related Reading

How to Increase Size of Disk Partition in...

October 5, 2023

How to Use Ansible to Manage Windows Machines

September 25, 2023

Fixing ‘The Network Path Was Not Found’ 0x80070035...

August 30, 2023

How to Install and Configure Ansible on Linux

August 27, 2023

Computer Doesn’t Turn Off After Shutting Down Windows...

August 26, 2023

1 comment

Kermit June 25, 2023 - 12:36 pm

No, I agree to disagree with the author unwise procedure, described in this article, because of next:
1. Internet is from many years now, completely not secure place where you can just download ClamAV virus definitions.
A “Man in the middle” attack is already a everyday procedure used by British, US, German etc. spy agencies. They do not hesitate to intercept each connection they can and replace key Servers ( as Microsoft Update servers and many others ) with their own version of those, therefore you be better using database already provided with ClamAV instead of overwriting it with some “internet” version.
2. No, You do not need to run “freshclam” as service, neither “ClamAV” as service in order to run a scan. Complete procedure to use ClamAV is in just 2 lines:

yum -y install clamav
clamscan -r -i /

And that is all.
Oh. “Windows OS Hub” – come from somebody who supports the Spy agencies “most friendly” OS called Windows.
See – not that I do not understand national security and stuffs, but you just do not know how far behind any ethical norms had gone the thugs who are above the laws and justice.

Reply

Leave a Comment Cancel Reply

Categories

  • Active Directory
  • Group Policies
  • Exchange Server
  • Microsoft 365
  • Azure
  • Windows 11
  • Windows 10
  • Windows Server 2022
  • Windows Server 2019
  • Windows Server 2016
  • PowerShell
  • VMWare
  • Hyper-V
  • Linux
  • MS Office

Recent Posts

  • Zabbix: How to Get Data from PowerShell Scripts

    October 27, 2023
  • Tracking Printer Usage with Windows Event Viewer Logs

    October 19, 2023
  • PowerShell: Configure Certificate-Based Authentication for Exchange Online (Azure)

    October 15, 2023
  • Reset Root Password in VMware ESXi

    October 12, 2023
  • How to Query and Change Teams User Presence Status with PowerShell

    October 8, 2023
  • How to Increase Size of Disk Partition in Ubuntu

    October 5, 2023
  • How to Use Ansible to Manage Windows Machines

    September 25, 2023
  • Installing Language Pack in Windows 10/11 with PowerShell

    September 15, 2023
  • Configure Email Forwarding for Mailbox on Exchange Server/Microsoft 365

    September 14, 2023
  • How to View and Change BIOS (UEFI) Settings with PowerShell

    September 13, 2023

Follow us

  • Facebook
  • Twitter
  • Telegram
Popular Posts
  • How to Configure MariaDB Master-Master/Slave Replication?
  • How to Mount Google Drive or OneDrive in Linux?
  • KVM: How to Expand or Shrink a Virtual Machine Disk Size?
  • Adding VLAN Interface in CentOS/Fedora/RHEL
  • Install and Configure SNMP on RHEL/CentOS/Fedor
  • Configuring High Performance NGINX and PHP-FPM Web Server
  • Configuring Routing on Linux (RHEL/CentOS)
Footer Logo

@2014 - 2023 - Windows OS Hub. All about operating systems for sysadmins


Back To Top