Configure SSL encryption and authentication for ClamAV cluster with high availability scanning

Advanced 45 min Apr 12, 2026
Ubuntu 24.04 Debian 12 AlmaLinux 9 Rocky Linux 9

Set up a secure ClamAV cluster with SSL/TLS encryption, certificate-based authentication, and load balancing for enterprise-grade antivirus scanning. This tutorial covers SSL certificate generation, encrypted inter-node communication, and HAProxy SSL termination.

Prerequisites

  • Root or sudo access
  • Multiple servers for cluster setup
  • Basic understanding of SSL certificates
  • Familiarity with ClamAV antivirus system
  • Knowledge of load balancing concepts

What this solves

Enterprise environments require secure, scalable antivirus scanning that protects sensitive data during transmission and ensures authenticated access between cluster nodes. This tutorial configures a ClamAV cluster with SSL encryption for all communications, certificate-based authentication, and load balancing with SSL termination for high availability scanning operations.

Step-by-step configuration

Update system packages

Start by updating your package manager to ensure you have the latest security patches.

sudo apt update && sudo apt upgrade -y
sudo dnf update -y

Install ClamAV and dependencies

Install ClamAV daemon, client tools, and OpenSSL for certificate management.

sudo apt install -y clamav clamav-daemon clamav-freshclam openssl haproxy
sudo dnf install -y clamav clamav-daemon clamav-freshclam openssl haproxy

Create SSL certificate authority

Generate a private Certificate Authority for signing cluster node certificates. This ensures only authorized nodes can join the cluster.

sudo mkdir -p /etc/clamav/ssl
sudo cd /etc/clamav/ssl
sudo openssl genrsa -out ca-key.pem 4096
sudo openssl req -new -x509 -days 3650 -key ca-key.pem -out ca-cert.pem -subj "/CN=ClamAV-CA/O=Internal/C=US"

Generate server certificates for each node

Create individual SSL certificates for each ClamAV cluster node. Replace NODE1_IP with your actual server IP addresses.

export NODE1_IP="203.0.113.10"
export NODE2_IP="203.0.113.11"
export NODE3_IP="203.0.113.12"
sudo openssl genrsa -out node1-key.pem 2048
sudo openssl req -new -key node1-key.pem -out node1-csr.pem -subj "/CN=${NODE1_IP}/O=ClamAV-Node/C=US"
sudo openssl x509 -req -days 365 -in node1-csr.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out node1-cert.pem
sudo openssl genrsa -out node2-key.pem 2048
sudo openssl req -new -key node2-key.pem -out node2-csr.pem -subj "/CN=${NODE2_IP}/O=ClamAV-Node/C=US"
sudo openssl x509 -req -days 365 -in node2-csr.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out node2-cert.pem
sudo openssl genrsa -out node3-key.pem 2048
sudo openssl req -new -key node3-key.pem -out node3-csr.pem -subj "/CN=${NODE3_IP}/O=ClamAV-Node/C=US"
sudo openssl x509 -req -days 365 -in node3-csr.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out node3-cert.pem

Set proper certificate permissions

Configure secure permissions for SSL certificates. The clamav user needs read access to certificates, but private keys must be protected from other users.

sudo chown -R root:clamav /etc/clamav/ssl
sudo chmod 750 /etc/clamav/ssl
sudo chmod 640 /etc/clamav/ssl/*.pem
sudo chmod 600 /etc/clamav/ssl/*-key.pem
Never use chmod 777. It gives every user on the system full access to your SSL private keys. Instead, use proper ownership and minimal permissions.

Configure ClamAV daemon with SSL on Node 1

Configure the first node's ClamAV daemon to use SSL encryption and bind to the network interface.

# Remove or comment out LocalSocket

LocalSocket /run/clamav/clamd.ctl

Network configuration with SSL

TCPSocket 3310 TCPAddr 203.0.113.10 MaxConnectionQueueLength 200 MaxThreads 20

SSL Configuration

SSL yes SSLCertificate /etc/clamav/ssl/node1-cert.pem SSLKey /etc/clamav/ssl/node1-key.pem SSLCACertificate /etc/clamav/ssl/ca-cert.pem SSLVerifyClient yes

Security settings

User clamav LogFile /var/log/clamav/clamav.log LogTime yes LogClean yes LogSyslog yes LogRotate yes ExtendedDetectionInfo yes

Performance tuning

ReadTimeout 300 CommandReadTimeout 30 SendBufTimeout 500 MaxQueue 1000 IdleTimeout 120 ExcludePath ^/proc/ ExcludePath ^/sys/

Configure ClamAV daemon with SSL on Node 2

Configure the second node with its specific IP address and certificate.

# Network configuration with SSL
TCPSocket 3310
TCPAddr 203.0.113.11
MaxConnectionQueueLength 200
MaxThreads 20

SSL Configuration

SSL yes SSLCertificate /etc/clamav/ssl/node2-cert.pem SSLKey /etc/clamav/ssl/node2-key.pem SSLCACertificate /etc/clamav/ssl/ca-cert.pem SSLVerifyClient yes

Security settings

User clamav LogFile /var/log/clamav/clamav.log LogTime yes LogClean yes LogSyslog yes LogRotate yes ExtendedDetectionInfo yes

Performance tuning

ReadTimeout 300 CommandReadTimeout 30 SendBufTimeout 500 MaxQueue 1000 IdleTimeout 120 ExcludePath ^/proc/ ExcludePath ^/sys/

Configure ClamAV daemon with SSL on Node 3

Configure the third node with its specific IP address and certificate.

# Network configuration with SSL
TCPSocket 3310
TCPAddr 203.0.113.12
MaxConnectionQueueLength 200
MaxThreads 20

SSL Configuration

SSL yes SSLCertificate /etc/clamav/ssl/node3-cert.pem SSLKey /etc/clamav/ssl/node3-key.pem SSLCACertificate /etc/clamav/ssl/ca-cert.pem SSLVerifyClient yes

Security settings

User clamav LogFile /var/log/clamav/clamav.log LogTime yes LogClean yes LogSyslog yes LogRotate yes ExtendedDetectionInfo yes

Performance tuning

ReadTimeout 300 CommandReadTimeout 30 SendBufTimeout 500 MaxQueue 1000 IdleTimeout 120 ExcludePath ^/proc/ ExcludePath ^/sys/

Configure FreshClam for signature updates

Configure automatic virus signature updates. This ensures all cluster nodes have the latest threat definitions.

DatabaseOwner clamav
UpdateLogFile /var/log/clamav/freshclam.log
LogTime yes
LogSyslog yes
LogRotate yes
DatabaseDirectory /var/lib/clamav
DNSDatabaseInfo current.cvd.clamav.net
DatabaseMirror db.local.clamav.net
DatabaseMirror database.clamav.net
MaxAttempts 5
Checks 24
CompressLocalDatabase yes
NotifyClamd /etc/clamav/clamd.conf

Create client authentication certificates

Generate client certificates for applications that will connect to the ClamAV cluster.

sudo openssl genrsa -out client-key.pem 2048
sudo openssl req -new -key client-key.pem -out client-csr.pem -subj "/CN=ClamAV-Client/O=ClamAV-Clients/C=US"
sudo openssl x509 -req -days 365 -in client-csr.pem -CA ca-cert.pem -CAkey ca-key.pem -CAcreateserial -out client-cert.pem
sudo chmod 644 /etc/clamav/ssl/client-cert.pem
sudo chmod 600 /etc/clamav/ssl/client-key.pem

Configure HAProxy for SSL termination and load balancing

Set up HAProxy to provide SSL termination and distribute scanning requests across cluster nodes with health checks.

global
    log stdout local0 info
    chroot /var/lib/haproxy
    stats socket /run/haproxy/admin.sock mode 660 level admin
    stats timeout 30s
    user haproxy
    group haproxy
    daemon
    ssl-default-bind-ciphers ECDHE+AESGCM:ECDHE+CHACHA20:RSA+AESGCM:RSA+AES:!aNULL:!MD5:!DSS
    ssl-default-bind-options ssl-min-ver TLSv1.2 no-tls-tickets

defaults
    mode tcp
    log global
    option tcplog
    option dontlognull
    option log-health-checks
    timeout connect 5000
    timeout client 300000
    timeout server 300000
    timeout check 5000
    retries 3

frontend clamav_ssl_frontend
    bind *:3311 ssl crt /etc/ssl/certs/haproxy-combined.pem ca-file /etc/clamav/ssl/ca-cert.pem verify required
    mode tcp
    default_backend clamav_cluster

frontend clamav_stats
    bind *:8404
    mode http
    stats enable
    stats uri /stats
    stats refresh 30s
    stats admin if TRUE

backend clamav_cluster
    mode tcp
    balance roundrobin
    option tcp-check
    tcp-check send "PING\n"
    tcp-check expect string "PONG"
    server node1 203.0.113.10:3310 check ssl verify required ca-file /etc/clamav/ssl/ca-cert.pem crt /etc/clamav/ssl/client-cert.pem
    server node2 203.0.113.11:3310 check ssl verify required ca-file /etc/clamav/ssl/ca-cert.pem crt /etc/clamav/ssl/client-cert.pem
    server node3 203.0.113.12:3310 check ssl verify required ca-file /etc/clamav/ssl/ca-cert.pem crt /etc/clamav/ssl/client-cert.pem

Create HAProxy SSL certificate bundle

HAProxy requires a combined certificate file containing both the certificate and private key.

sudo openssl genrsa -out haproxy-key.pem 2048
sudo openssl req -new -key haproxy-key.pem -out haproxy-csr.pem -subj "/CN=clamav-cluster.example.com/O=HAProxy/C=US"
sudo openssl x509 -req -days 365 -in haproxy-csr.pem -CA /etc/clamav/ssl/ca-cert.pem -CAkey /etc/clamav/ssl/ca-key.pem -CAcreateserial -out haproxy-cert.pem
sudo cat haproxy-cert.pem haproxy-key.pem > /etc/ssl/certs/haproxy-combined.pem
sudo chmod 600 /etc/ssl/certs/haproxy-combined.pem
sudo chown haproxy:haproxy /etc/ssl/certs/haproxy-combined.pem

Configure firewall rules

Open necessary ports for the ClamAV cluster and HAProxy load balancer.

sudo ufw allow 3310/tcp comment "ClamAV SSL"
sudo ufw allow 3311/tcp comment "HAProxy ClamAV SSL Frontend"
sudo ufw allow 8404/tcp comment "HAProxy Stats"
sudo ufw reload
sudo firewall-cmd --permanent --add-port=3310/tcp
sudo firewall-cmd --permanent --add-port=3311/tcp
sudo firewall-cmd --permanent --add-port=8404/tcp
sudo firewall-cmd --reload

Start and enable services

Start all ClamAV daemons and HAProxy on each respective server.

sudo systemctl enable --now clamav-freshclam
sudo systemctl enable --now clamav-daemon
sudo systemctl enable --now haproxy

Create SSL client connection script

Create a helper script for testing encrypted connections to the ClamAV cluster.

#!/bin/bash

ClamAV SSL Client Connection Script

CLAMAV_HOST="203.0.113.10" CLAMAV_PORT="3311" CLIENT_CERT="/etc/clamav/ssl/client-cert.pem" CLIENT_KEY="/etc/clamav/ssl/client-key.pem" CA_CERT="/etc/clamav/ssl/ca-cert.pem" if [ $# -eq 0 ]; then echo "Usage: $0 " exit 1 fi FILE_TO_SCAN="$1" if [ ! -f "$FILE_TO_SCAN" ]; then echo "Error: File '$FILE_TO_SCAN' not found" exit 1 fi

Use clamdscan with SSL options

clamdscan --config-file=/dev/null \ --stream \ --fdpass \ --multiscan \ "$FILE_TO_SCAN" echo "Scan completed via encrypted connection"
sudo chmod 755 /usr/local/bin/clamav-ssl-scan

Verify your setup

Test SSL connectivity, certificate authentication, and load balancer functionality.

# Check ClamAV daemon status on each node
sudo systemctl status clamav-daemon
sudo systemctl status clamav-freshclam
# Test SSL connection to individual nodes
openssl s_client -connect 203.0.113.10:3310 -cert /etc/clamav/ssl/client-cert.pem -key /etc/clamav/ssl/client-key.pem -CAfile /etc/clamav/ssl/ca-cert.pem -verify_return_error
# Test HAProxy SSL termination
curl -k https://203.0.113.10:8404/stats
# Test encrypted scanning
echo "X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*" > /tmp/eicar.txt
/usr/local/bin/clamav-ssl-scan /tmp/eicar.txt
# Check cluster health through HAProxy
echo "PING" | openssl s_client -connect 203.0.113.10:3311 -cert /etc/clamav/ssl/client-cert.pem -key /etc/clamav/ssl/client-key.pem -CAfile /etc/clamav/ssl/ca-cert.pem -quiet

Common issues

SymptomCauseFix
SSL handshake failureCertificate verification failedCheck certificate CN matches server IP, verify CA chain
Connection refused on port 3310ClamAV not binding to network interfaceCheck TCPAddr setting in clamd.conf, verify firewall rules
HAProxy backend servers marked as downSSL client certificate not configuredVerify client certificate path in HAProxy backend configuration
Permission denied accessing certificatesWrong file ownership or permissionssudo chown -R root:clamav /etc/clamav/ssl && sudo chmod 640 *.pem
ClamAV daemon won't startSSL certificate file not foundVerify certificate paths in clamd.conf, check file permissions
Client authentication failedClient certificate not trusted by CARegenerate client certificate with correct CA signing

Next steps

Automated install script

Run this to automate the entire setup

Need help?

Don't want to manage this yourself?

We handle infrastructure security hardening for businesses that depend on uptime. From initial setup to ongoing operations.