ClamAV Setup and Configuration Tutorial - Fedora 41
Back
Previous Article: Installing SAModManager on Linux Bottles
Next Article: Setup KeePassXC with Librewolf using Flatpaks
Author: Yiannis Charalambous
Reading Time: 9 minutes
Tags: Tutorial
Guide based on this blog post by Daniel Aleksandersen and the ArchLinux Wiki. None of these worked perfectly on their own and some modifications were made to accommodate for that. The setup that this configuration belongs to is:
- Laptop (This guide is not meant for servers, additional configuration is most likely required)
- Fedora 41
Fedora has some extra configuration that needs to happen before setting up ClamAV to work properly. The components are:
clamd
freshclam
Install the packages:
|
|
Start by enabling the antivirus scanning option of SELinux:
|
|
freshclam
Start by generating initial configuration for freshclam. Freshclam is ran under the user clamupdate
.
|
|
Apply the following diff:
|
|
Run a virus definition update and additionally enable the freshclam service:
|
|
Enabling the service will perform periodic updating. This is in contrast to the blog post that used cron for this functionality.
clamd
Start by generating initial configuration for the daemon. The scanning service will be ran under the user clamscan
.
|
|
The following options were changed in my file, which are based of the ArchLinux guide’s recommended settings, however, not exact:
|
|
VirusEvent
You might have noticed the VirusEvent
option that triggers when a virus is found is set to execute /opt/clamav/virus-event.sh
. Set it up by running the following commands:
|
|
Save the following file contents:
Set permissions:
|
|
Starting the Daemon
Controlled through SystemD unit files. The daemon has the possibility to freeze your system (a lot of times), so the blog post recommends to set system resource limits by overriding the systemd files.
|
|
Add the following overrides:
[Service]
Nice=18
IOSchedulingClass=idle
CPUSchedulingPolicy=idle
Activate the daemon:
|
|
Enabling OnAccessScan
OnAccessScan allows ClamAV to scan files on demand as the users access them. This is useful to have as it provides constant security at the cost of speed. To enable the service that runs the OnAccessScan, edit the service to add passing file-descriptors instead of paths:
|
|
Add the following overrides (the reason is explained in the ArchLinux guide):
[Service]
ExecStart=
ExecStart=/usr/sbin/clamonacc -F --fdpass --config-file=/etc/clamd.d/scan.conf
Reload and enable:
|
|
Testing
This will test if a fake virus is detected. The file in the URL is harmless (it’s a txt file).
Manual
|
|
Realtime Protection
cd ~/Downloads
wget https://secure.eicar.org/eicar.com.txt
cat eicar.com.txt
Check the logs:
|
|
If a notification did not appear, then please look at the workaround for VirusEvent below, as you may have encountered a ClamAV bug.
Using clamdscan
With clamd running in the background, we can use clamdscan. It’s like clamscan but uses the config from /etc/clamd.d/scan.conf
as it uses the clamd@scan
daemon we enabled previously:
|
|
File Permission Issues
You might notice that trying to use clamdscan, gives you a variety of errors:
--------------------------------------
/home/yiannis: File path check failure: Permission denied. ERROR
----------- SCAN SUMMARY -----------
Infected files: 0
Total errors: 1
Time: 0.002 sec (0 m 0 s)
Start Date: 2025:02:17 23:45:20
End Date: 2025:02:17 23:45:20
In order to fix this issue, the parameter --fdpass
needs to be included; clamdscan -mil clamav.log --fdpass $HOME
. This will make clamscan (ran under the $USER
) pass the file descriptor to clamd (ran under clamscan), allowing the clamscan user to bypass the file permissions of the home folder.
LocalSocket Issues
At this point, another error with local socket permissions should appear:
ERROR: Could not connect to clamd on LocalSocket /var/run/clamd.scan/clamd.socket
This is caused because the clamdscan process (ran under $USER
) does not have permissions to access the socket; owned by clamscan and part of the virusgroup group. The solution to this:
|
|
Log out and log back in. Now clamdscan should work (don’t forget to pass --fdpass
.
VirusEvent Workaround
There’s an issue that ClamAV is facing where VirusEvent
is not working. A user suggested a workaround where we deploy an extra script to read the logs and trigger the virus event manually. Keep this while the issue is open. After the issue is resolved, you can delete all the work done in this section.
Notifier Script
Start by creating a script the notifier script:
|
|
This script is responsible for scanning the log file and creating the virus events.
Monitor Script
Create the monitor script that will feed the log file to the notifier script.
|
|
This script pipes the output of the journal which contains the logs from the OnAccessScan service to the notifier script.
Set appropriate permissions for both scripts:
|
|
Service File
Now create a service file to run these two scripts:
|
|
This simply waits for all other services to start, then run the script as root:
[Unit]
Description=ClamAV On-Access Notifier (Workaround for VirusEvent being broken in ClamAV)
Requires=clamav-clamonacc.service
After=clamav-clamonacc.service syslog.target network.target
[Service]
Type=simple
User=root
ExecStart=/opt/clamav/clamonacc-log-monitor.sh
Restart=always
[Install]
WantedBy=multi-user.target
Enable the service:
|
|
Reversing the Workaround
Effort was put to make the VirusEvent workaround changes as minimal as possible. When the issue is fixed, reverse the changes by running the following commands:
|
|
These commands stop and delete the service from the system and delete the remaining scripts that were created.
Install GUI - ClamTK
ClamTK is a GUI front-end for ClamAV. Its main limitation is that it doesn’t allow you to configure ClamAV in any meaningful way. It contains some basic utilities such as scanning files and directories. To install it run the following command:
|
|
I personally don’t find it that useful.
Existing Issues
While my research into this program has resolved most of the issues, I have still am facing the following problems. If you know how to resolve them, please get in touch.
Duplicate Reports in clamav-clamonacc
- It can be observed that when running:
journalctl --follow -eu clamav-clamonacc
, and an infected file is accessed, multiple entries are created. I don’t think this is intended behaviour.
Running clamdscan
The following problems are produced when running the command:
|
|
STDOUT
- The output of the command is a lot of these lines:
LibClamAV Warning: cli_realpath: Invalid arguments.
LOG FILE
- When running clamdscan, I get a
WARNING: [FILE]: Not supported file type
on some entries. I thought that the--infected
in conjunction with--quiet
option would work. This is not the case! - When running clamdscan, I get a
[FILE]: Failed to open file
on some entries. I thought that the--infected
in conjunction with--quiet
option would work. This is not the case!