Linux – ClamD: cannot change socket location

clamavlinuxUbuntu

Ubuntu 20.04.2
ClamAV 0.102.4

I want to use a different value for ClamD's LocalSocket directive but keep getting the following error:

!LOCAL: Socket file /var/run/clamd.scan/clamd.sock could not be bound: Permission denied

The defaults in /etc/clamav/clamd.conf are:

LocalSocket /var/run/clamav/clamd.ctl
FixStaleSocket true
LocalSocketGroup clamav
LocalSocketMode 666
User clamav

I changed the LocalSocket value to:

LocalSocket /var/run/clamd.scan/clamd.sock
FixStaleSocket true
LocalSocketGroup clamav
LocalSocketMode 666
User clamav

Then created the new directory and set perms and ownership. Matching that of /var/run/clamav/ where the socket file is able to be created.

mkdir /var/run/clamd.scan
chown clamav:root /var/run/clamd.scan/
chmod 755 /var/run/clamd.scan/

Restarted clam and getting the Permission Denied error from above

systemctl restart clamav-daemon && systemctl status clamav-daemon.service

Directory ownerships and perms are the same:

drwxr-xr-x  2 clamav   root         40 Feb 26 18:52 clamav/
drwxr-xr-x  2 clamav   root         60 Feb 26 19:12 clamd.scan/

I tried temporarily changing the perms of /var/run/clamd.scan/ to 777 but still get the same error after restarting clamd.

I'm able to create a file in that directory as the clamav user if I try:

su - clamav -s /bin/bash -c "cd /var/run/clamd.scan && touch clamd.sock"

So I don't understand why I would be getting that Permission Denied. Any advice? I must be missing something.

Best Answer

I had an issue similar to yours : after a fresh install, clamd was not able to fully use its socket and complained when I launched it manually :

$ sudo clamd
!LOCAL: Socket file /var/run/clamav/clamd.ctl could not be removed: Permission denied

(I'm not certain this is the right way to start clamd but still) So I set the permissions as follows :

drwxrwxr-x  2 root   clamav   60 mars  21 09:49 clamav
srw-rw-rw-  1 clamav clamav    0 mars  21 09:51 clamd.ctl

And then sudo clamd returns without any error message, so clamd is started !

I'm uneasy with the idea that others have rw permissions on this socket, but if I remove them, clamd sets them back again when I start it...

I hope that it can help !