2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Ubuntu 18.04にclamavをインストールして定期的にシステム全体のスキャンをclamdscanで行う方法

Last updated at Posted at 2019-12-11

概要

Ubuntu 18.04にclamavをインストールして定期的にシステム全体のウイルススキャンをclamdscanで実行したい人のためのセットアップ手順を紹介する。

背景

Ubuntu 18.04にclamavをインストールして$HOMEをclamscanするまでは素直に利用できたが、より高速なclamdscanを用いてシステム全体をスキャンしようとすると以下に示す2つのエラーによりスキャンができなかった。

  1. Can't connect to clamd through /var/run/clamav/clamd.ctl: No such file or directory
  2. lstat() failed: Permission denied. ERROR
[   50.631849] audit: type=1400 audit(1576039159.748:43): apparmor="DENIED" operation="open" profile="/usr/sbin/clamd" name="/" pid=849 comm="clamd" requested_mask="r" denied_mask="r" fsuid=0 ouid=0

成功したセットアップ手順

まずは成功したセットアップを掲載。問題とそれらへの対応は後述(後日)。

sudo su

apt update
apt install -y clamav clamav-daemon
systemctl stop clamav-freshclam
freshclam
systemctl start clamav-freshclam
systemctl enable clamav-freshclam

systemctl stop clamav-daemon
rm -rf /run/clamav

sed 's@ExecStartPre=/bin/chown@#ExecStartPre=/bin/chown@' /etc/systemd/system/clamav-daemon.service.d/extend.conf

switches=(
LocalSocket
FixStaleSocket
LocalSocketGroup
LocalSocketMode
User
ScanOnAccess
)

for switch in  ${switches[@]}
do
    sed -i "s/$switch/#$switch/" /etc/clamav/clamd.conf
done

cat << 'EOS' >> /etc/clamav/clamd.conf
User root
ScanOnAccess true
OnAccessMountPath /home
VirusEvent /usr/local/bin/clamd-response
TCPSocket 3310
TCPAddr 127.0.0.1
EOS

cat << 'EOS' > /usr/local/bin/clamd-response
#!/bin/sh
echo "$(date) - $CLAM_VIRUSEVENT_VIRUSNAME > $CLAM_VIRUSEVENT_FILENAME" >> /var/log/clamav/infected.log
mv $CLAM_VIRUSEVENT_FILENAME $CLAM_VIRUSEVENT_FILENAME.virus
EOS
chmod +x /usr/local/bin/clamd-response

cat << 'EOS' >> /etc/apparmor.d/local/usr.sbin.clamd
/ r,
/** r,
EOS
apparmor_parser -R /etc/apparmor.d/usr.sbin.clamd

systemctl daemon-reload
systemctl enable clamav-daemon

apt install -y clamtk
sed -i 's/Exec=clamtk %F/Exec=env LC_TIME=C clamtk %F/g' /usr/share/applications/clamtk.desktop

reboot # 途中再起動せずに色々触ってハマったのでオマジナイ。もしかしたら不要かも
2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?