Skip to content

ClamAV Anti Virus and Anti Malware

When running freshclam or clamd as a service, create a service account.

  • ClamAV Daemon (clamd) can scan for virues that uses libclamav using:
    • clamdscan - scanner, command-line tool for simple scans
    • on-access scanning via clamd
    • clamdtop - resource monitoring interface for clamd
  • These are some tools that allow for testing and management of signatures:
    • clambc - bytecode tester
    • sigtool - general tests/analysis
    • freshclam - update signature database to latest

More complex tools ClamAV need some configuration.

ClamAV does provide example configurations:

  • clamd.conf - for ClamAV Daemon and related tools
  • freshclam.conf - for freshclam signature database updates
  • clamav-milter can be attached to clamd for mail scanning

Uses can use clamconf to check configurations by each tool.

  • Example: clamav install on Ubuntu with apt install will place configs in /etc/clamav.
  • Compilation from source requires uses to create freshclam.conf, clamd.conf, and clamav-milter.conf manually. The install will place files is different directories.
Terminal window
# Unix/Linux: Generate example configurations if you do not have them
clamconf -g freshclam.conf > freshclam.conf
clamconf -g clamd.conf > clamd.conf
clamconf -g clamav-milter.conf > clamav-milter.conf

See First Time Set up for Windows as well

  • Automatic database update tool. Two modes are available:
    • Interactive: on demand command line
    • Daemon: runs in the background and updates automatically

See freshclam.conf for more details on requires to get freshclam running regularly:

  • /var/log configuration and permissions
  • Configuration file
  • Start daemon
  • crontab update to regularly get update
  • Further settings in the example configuration and popular options

Configuration for clamd daemon. Users need to edit the example configuration and at minimum comment out the example line.

See clamd.conf for details on:

  • Minimum edits required
  • Local socket configuration
  • Popular options in configuration file

Use man clamd.conf for manual. Also read through the example configuration file for comments and options.

  • On-Access Scanning Can be configured
  • Mail filtering tool, requires clamd to be running
  • Separate configuration and log files from clamd

Requirements for users and privileges related to running freshclam, clamd, updates, and scanning. DatabaseOwner in freshclam.conf should own database directory to download signatures.

Used in Linux distributions like Fedora with SELinux enabled use the non-standard antivirus_can_scan_system option instead of clamd_can_scan_system. You may need to manually enable the non-standard option, otherwise there will be a freshclam message.

clamconf is a CLI tool to check configuration files for ClamAV tools and can generate example configuration files.

  • Before you can start the ClamAV scanning engine (using either clamd or clamscan), you must first have ClamAV Virus Database (.cvd) file(s) installed

  • With a valid freshclam.conf configuration file, run freshclam. It will connect to the ClamAV virus signature database network.

  • Ubuntu specific possible error:

    • Important: It is common on Ubuntu after a fresh install to see the following error the first time you use ClamAV:

freshclam: error while loading shared libraries: libclamav.so.7: cannot open shared object file: No such file or directory

You can fix this error by using ldconfig to rebuild the library search path.

sudo ldconfig

See Signature management for further tools.

  • Make sure clamd is started with a valid configuration
  • Use command clamdscan to scan files and directories. It will use the running clamd daemon to scan files.

Example from Arch Wiki ClamAV

Terminal window
# Check Freshclam signatures database
systemctl status clamav-freshclam
clamdscan --fdpass <directory>
# Multithread scan on justin's user directory while running as user "justin"
clamdscan --multiscan --fdpass /home/justin
# Scan all files as root
clamdscan --multiscan --fdpass /
# Here the --multiscan parameter enables clamd to scan the contents of the directory in parallel using available threads. --fdpass parameter is required to pass the file descriptor permissions to clamd as the daemon is running under clamav user and group, used when scan and running a different users than clamav
# The number of available threads for clamdscan is determined in /etc/clamav/clamd.conf via MaxThreads parameter clamd.conf(5). Even though you may see that the number of MaxThreads specified is more than one (current default is 10), when you start the scan using clamdscan from command line and do not specify --multiscan option, only one effective CPU thread will be used for scanning.

clamdtop is a tool to monitor one or multiple instances of clamd. It has a colorized ncurses interface, which shows each job queued, memory usage, and information about the loaded signature database for the connected clamd instance(s). By default it will attempt to connect to the local clamd as defined in clamd.conf

  • The “ClamOnAcc” applications provides on access canning for Linux and is real-time protection that uses clamd to scan files when they are accessed. Default only notifies the user and follows actions prompted by user at command line.
  • If can be set up in clamd.conf
  • clamscan is a command line tool one time scanning of files and directories. It does not require a running clamd. It will create a new engine and load the virus database each time, scan the files and exit providing a report.
Terminal window
# Only scan files in current directory
clamscan .
# Scan all files in current and lower directories
clamscan --recursive .
# Scan all files on the system
clamscan --recursive /
# Similar to above with exclusions
clamscan --recursive / --exclude-dir=/sys --exclude-dir=/proc --exclude-dir=/dev --exclude-dir=/run

clamscan and clamdscan are able to scan the virtual memory of currently executing processes. To do so, use the –memory option:

clamscan --memory

The --kill and --unload options allow for killing/unloading infected loaded modules.