Run ClamAV as a Daemon

For Ubuntu 16.04

Install clamav-daemon & clamav-freshclam

  1. apt-get install clamav-daemon clamav-freshclam

You should run Clamd with a root permission to scan any files.
Edit the conf /etc/clamav/clamd.conf,change the following line:

  1. LocalSocketGroup root
  2. User root

Start the clamav-daemon

  1. systemctl start clamav-daemon
  • Test the software
  1. $ curl https://www.eicar.org/download/eicar.com.txt | clamdscan -

The output must include:

  1. stream: Eicar-Test-Signature FOUND

For CentOS 7

Install Clamd

  1. yum install epel-release
  2. yum install clamav-server clamav-data clamav-filesystem clamav-lib clamav-update clamav clamav-devel

Run freshclam

  • Configure the freshclam to updating database
  1. cp /etc/freshclam.conf /etc/freshclam.conf.bak
  2. sed -i '/^Example/d' /etc/freshclam.conf
  • Create the init script
  1. cat > /usr/lib/systemd/system/clam-freshclam.service << 'EOF'
  2. # Run the freshclam as daemon
  3. [Unit]
  4. Description = freshclam scanner
  5. After = network.target
  6. [Service]
  7. Type = forking
  8. ExecStart = /usr/bin/freshclam -d -c 4
  9. Restart = on-failure
  10. PrivateTmp = true
  11. [Install]
  12. WantedBy=multi-user.target
  13. EOF
  • Boot up
  1. systemctl enable clam-freshclam.service
  2. systemctl start clam-freshclam.service

Configure Clamd

  1. cp /usr/share/clamav/template/clamd.conf /etc/clamd.conf
  2. sed -i '/^Example/d' /etc/clamd.conf

You should run Clamd with a root permission to scan any files.
Edit the /etc/clamd.conf,change the following line:

  1. User root
  2. ...
  3. LocalSocket /var/run/clamd.sock

Run Clamd

  • Create the init script
  1. cat > /etc/init.d/clamd << 'EOF'
  2. case "$1" in
  3. start)
  4. echo -n "Starting Clam AntiVirus Daemon... "
  5. /usr/sbin/clamd
  6. RETVAL=$?
  7. echo
  8. [ $RETVAL -eq 0 ] && touch /var/lock/subsys/clamd
  9. ;;
  10. stop)
  11. echo -n "Stopping Clam AntiVirus Daemon... "
  12. pkill clamd
  13. rm -f /var/run/clamav/clamd.sock
  14. rm -f /var/run/clamav/clamd.pid
  15. RETVAL=$?
  16. echo
  17. [ $RETVAL -eq 0 ] && rm -f /var/lock/subsys/clamd
  18. ;;
  19. esac
  20. EOF
  1. chmod +x /etc/init.d/clamd
  • Boot up
  1. chkconfig clamd on
  2. service clamd start
  • Test the software
  1. $ curl https://www.eicar.org/download/eicar.com.txt | clamdscan -

The output must include:

  1. stream: Eicar-Test-Signature FOUND