Skip to content

Both.org

News, Opinion, Tutorials, and Community for Linux Users and SysAdmins

Primary Menu
  • About Us
  • Computers 101
    • Hardware 101
    • Operating Systems 101
  • End of 10 Events
    • Wake Forest, NC, — 2025-09-20
  • Linux
    • Why I use Linux
    • The real reason we use Linux
  • My Linux Books
    • systemd for Linux SysAdmins
    • Using and Administering Linux – Zero to SysAdmin: 2nd Edition
    • The Linux Philosophy for SysAdmins
    • Linux for Small Business Owners
    • Errata
      • Errata for The Linux Philosophy for SysAdmins
      • Errata for Using and Administering Linux — 1st Edition
      • Errata for Using and Administering Linux — 2nd Edition
  • Open Source Resources
    • What is Open Source?
    • What is Linux?
    • What is Open Source Software?
    • The Open Source Way
  • Write for us
    • Submission and Style guide
    • Advertising statement
  • Downloads
  • Home
  • Linux Malware scanning using ClamAV
  • Anti-Malware
  • In Depth
  • Linux
  • Security

Linux Malware scanning using ClamAV

Gaurav Kamathe July 7, 2024 7 minutes read
malware-291793476-cropped

Image via Creative Commons, modified by Both.org

Introduction

There are many different ways of protecting a system, right from keeping the software up-to-date, to removing unnecessary packages, turning off unneeded services, to running a firewall etc. Amongst these one also needs to deal with malware, which needs to be detected, identified, quarantined or removed. ClamAV is an open-source antivirus engine for detecting malware and malicious software. ClamAV is available for multiple platforms like Unix, Linux, Windows, MacOS etc and works on a variety of file formats like PE executables, ELF and Mach-O to name a few. In this article we shall see how you can utilize ClamAV for your malware scanning needs.

Installation

To install ClamAV I will be using a Fedora system however the instructions should work on RHEL or any RPM based Operating systems like CentOS etc.

$ cat /etc/fedora-release
Fedora release 36 (Thirty Six)
$

We will first utilize our package manager dnf to install three packages as shown in the command line below, we will see what these packages are and its contents further.

$ dnf install clamav clamd clamav-update

Contents of packages

The first package we installed is clamav, as stated below it contains all the end-user tools which helps a user run the clamav utility to scan a system for malware. In addition it has some helpful utilities to understand malware signatures, view ClamAV configuration settings and even submit malware samples back to ClamAV.

$ rpm -qi clamav-0.103.8-3.fc36.x86_64 | grep ^Summary
Summary : End-user tools for the Clam Antivirus scanner
$
$ rpm -ql clamav-0.103.8-3.fc36.x86_64 | grep bin
/usr/bin/clambc
/usr/bin/clamconf
/usr/bin/clamdscan
/usr/bin/clamdtop
/usr/bin/clamscan
/usr/bin/clamsubmit
/usr/bin/sigtool
/usr/sbin/clamonacc
$

The next package we installed is clamav-update. New malware strains are created and released almost daily. Malware hunters have to keep up with these new variants which are analyzed and a signature is created for them. These signatures in turn help a user to detect the latest viruses. It makes sense to keep your malware signatures up-to-date. ClamAV provides a freshclam utility which checks if new signatures are available and downloads them onto your system for future scans.

$ rpm -qi clamav-update-0.103.8-3.fc36.x86_64 | grep ^Summary
Summary : Auto-updater for the Clam Antivirus scanner data-files
$
$ rpm -ql clamav-update-0.103.8-3.fc36.x86_64 | grep bin
/usr/bin/freshclam
$

And finally the clamd package which consists of the clamd daemon which allows us to run ClamAV as service in the background.

$ rpm -qi clamd-0.103.8-3.fc36.x86_64 | grep ^Summary
Summary : The Clam AntiVirus Daemon
$
$ rpm -ql clamd-0.103.8-3.fc36.x86_64 | grep bin
/usr/sbin/clamd
$

Getting latest signatures using freshclam

Once ClamAV is installed let us update the latest malware signatures using the freshclam utility as shown below. In case you have SELinux enabled you need perform the following additional step as outline in configuration settings.

$ setsebool -P antivirus_can_scan_system 1

On running freshclam you should see it updating some .cvd files which we will talk about later in the article.

$ freshclam
<snip>
ClamAV update process started at Tue Apr 4 02:44:39 2023
daily database available for download (remote version: 26864)
daily.cvd updated (version: 26864, sigs: 2028069, f-level: 90, builder: raynman)
main database available for download (remote version: 62)
main.cvd updated (version: 62, sigs: 6647427, f-level: 90, builder: sigmgr)
bytecode database available for download (remote version: 334)
bytecode.cvd updated (version: 334, sigs: 91, f-level: 90, builder: anvilleg)
<snip>
$

The malware signatures are stored within the /var/lib directory of your filesystems. Running the file command on the main.cvd file identifies it as a “Clam Antivirus database” file.

$ cd /var/lib/clamav/
$ pwd
/var/lib/clamav
$ ls
bytecode.cvd daily.cvd freshclam.dat main.cvd
$ file /var/lib/clamav/main.cvd
/var/lib/clamav/main.cvd: Clam AntiVirus database (with buildtime), 16 Sep 2021 08-32 -0400, version 62, 6647427 signatures, level 90, builder sigmgr, with gzip compressed data, max compression, from Unix, original size modulo 2^32 464052736
$

Explore existing signatures using sigtool

We now know where the antivirus database is located but how many malware signatures does it consist of ? sigtool is a handy utility which helps you work with malware signatures. In the output below I ran it against the main.cvd database and it showed that it contains 6647427 malware signatures followed by the MD5 hash and signature.

$ sigtool -i /var/lib/clamav/main.cvd
File: /var/lib/clamav/main.cvd
Build time: 16 Sep 2021 08:32 -0400
Version: 62
Signatures: 6647427
Functionality level: 90
Builder: sigmgr
MD5: 137eccce31aacb21b5a98bb8c21cefd6
Digital signature: twaJBls8V5q64R7QY10AatEtPNuPWoVoxTaNO1jpBg7s5jIMMXpitgG1000YLp6rb0TWkEKjRqxneGTxuxWaWm7XBjsgwX2BRWh/y4fhs7uyImdKRLzQ5y8e2EkSChegF/i8clqfn+1qetq9j4gbktJ3JZpOXPoHlyr2Dv9S/Bg
Verification OK.
$

If you wish to see the actual signatures within the database you need to unpack it first. Follow the steps below, and start by creating a new temp directory.

$ mkdir -p /tmp/sigs
$
$ cd /tmp/sigs/
$ pwd
/tmp/sigs
$

Next, use sigtool to unpack the antivirus database to the above temp directory, once unpacked you should see a bunch of files within the directory. Use any text editor to open the files and see its contents

$ sigtool --unpack /var/lib/clamav/main.cvd
COPYING main.cdb main.crb main.fp main.hdb main.hsb main.info main.ldb main.mdb main.msb main.ndb main.sfp
$ 

Scanning files and directories using clamscan

Finally, we can run clamscan against a file or a directory using -r which internally uses the signatures database to see if it found any match against the files that it scanned. There are many handy command line arguments which clamscan provides, I encourage you to read its man page for more details.

$ clamscan /usr/bin/ls
$ clamscan -r /usr/bin/
$ clamscan --log=/tmp/clamav_test_run.log -r /usr/bin

ClamAV Configuration settings

ClamAV is highly configurable as per your requirements. You can use the scan.conf file to check your current configuration and make new changes. There is also a handy clamconf utility which dumps your entire system configuration to the screen.

$ ls -l /etc/clamd.d/scan.conf
-rw-r--r--. 1 root root 26665 Feb 20 11:54 /etc/clamd.d/scan.conf
$ clamconf
Checking configuration files in /etc
Config file: clamd.d/scan.conf
------------------------------
AlertExceedsMax disabled
Config file: freshclam.conf
---------------------------
LogFileMaxSize = "1048576"
LogTime disabled
LogSyslog disabled
<< snip >>
$

Running Clamav daemon

Running ClamAV once a while is good, however remember it also ships a multithreaded clamd daemon so one can also configure it as a service which runs continuously in the background and can be managed by the systemd as shown in the example below. Also make note that if you intent to run the clamav service its best to add a service account

$ ls -l /usr/lib/systemd/system/clamd@.service
-rw-r--r--. 1 root root 398 Feb 20 11:44 /usr/lib/systemd/system/clamd@.service
$
$ systemctl status clamd@service
○ clamd@service.service - clamd scanner (service) daemon
Loaded: loaded (/usr/lib/systemd/system/clamd@.service; disabled; vendor preset: disabled)
Active: inactive (dead)
Docs: man:clamd(8)
man:clamd.conf(5)
https://www.clamav.net/documents
$

Conclusion

ClamAV is a healthy open source project which is actively developed and maintained by the Cisco Talos Threat Intelligence team. I have barely touched the surface of what ClamAV is capable of. I highly recommend users to check its documentation to understand its value and decide if it would be suitable for your malware scanning needs. Also check out the variety of community projects related to ClamAV that you can contribute to.

Tags: clamav Security

Post navigation

Previous: Is Linux Still Linux?
Next: Tips for using the ‘ls’ command in Linux

Related Stories

connections_wires_sysadmin_cable
  • Linux
  • Networking
  • Router

How to Make your Linux Box Into a Router

David Both April 29, 2026
f44-01-day-cropped
  • Fedora
  • Linux
  • Upgrades

Fedora 44 Released

David Both April 28, 2026
command_line_prompt
  • Command Line
  • Linux
  • Programming

Writing a replacement seq command

Jim Hall April 27, 2026

System upgrades this Sunday, May 3

Tools illustrationFedora 44 was released this week and I’ve upgraded all my systems except for the two that directly affect Both.org. I’ll be upgrading the hosts for my server and firewall to Fedora 44 this Sunday afternoon, May 3.

Both.org will be down for most of the afternoon for these upgrades.

Thanks for your patience.

Random Quote

The value of any software lies in its usefulness not in its price.

— Linus Torvalds

Why I’ve Never Used Windows

On February 12 I gave a presentation at the Triangle Linux Users Group (TriLUG) about why I use Linux and why I’ve never used Windows.

Here’s the link to the video: https://www.youtube.com/live/uCK_haOXPFM 

Why there’s no such thing as AI

Last October at All Things Open (ATO) I was interviewed by Jason Hibbits of We Love Open Source. It’s posted in the article “Why today’s AI isn’t intelligent (yet)“.

Technically We Write — Our Partner Site

Our partner site, Technically We Write, has published a number of articles from several contributors to Both.org. Check them out.

Technically We Write is a community of technical writers, technical editors, copyeditors, web content writers, and all other roles in technical communication.

Subscribe to Both.org

To comment on articles, you must have an account.

Send your desired user ID, first and last name, and an email address for login (this must be the same email address used to register) to subscribe@both.org with “Subscribe” as the subject line.

You’ll receive a confirmation of your subscription with your initial password as soon as we are able to process it.

Administration

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

License and AI Statements

Both.org aims to publish everything under a Creative Commons Attribution ShareAlike license. Some items may be published under a different license. You are responsible to verify permissions before reusing content from this website.

The opinions expressed are those of the individual authors, not Both.org.

You may not use this content to train AI.

 

Advertising Statement

Both.org does not sell advertising on this website.


Advertising may keep most websites running—but at Both.org, we’re committed to keeping our corner of the web ad-free. Both.org does not sell advertising on the website. Nor do we offer sponsored articles at this time. We’ll update this page if our position on sponsorships changes.

We want to be open about how the website is funded. Both.org is supported entirely by David Both and a few other dedicated individuals.

 

 

Copyright © All rights reserved. | MoreNews by AF themes.