Ubuntu 22.04 ClamAV 反病毒软件部署与命令详解
Ubuntu 22.04 系统 ClamAV 开源反病毒软件的安装(在线 apt 与离线 deb)与 clamscan/freshclam/clamdscan 全部常用命令参数实测详解,含病毒库更新、EICAR 查杀与 clamtk 图形界面
Ubuntu 22.04 ClamAV 反病毒软件部署与命令详解
目标:掌握 Ubuntu 22.04 LTS 下 ClamAV 1.5.4 开源反病毒软件的在线(apt)/ 离线(deb)安装、病毒库更新机制,以及 clamscan / freshclam / clamd / clamdscan / clamconf / sigtool 六大工具与 clamtk 图形界面的每一个常用命令与参数用途,并通过 EICAR 标准测试文件完成真实查杀演练。本文全部命令回显已在 CentOS 8 / Ubuntu 22.04 真实环境实测通过
一、环境信息
本文所有命令均在一套 Ubuntu 22.04.5 LTS 系统(systemd 托管,apt 包管理器) 上真实执行,关键环境参数如下:
| 项目 | 版本 / 值 | 实测依据 |
|---|---|---|
| 操作系统 | Ubuntu 22.04.5 LTS(jammy) | cat /etc/os-release → PRETTY_NAME="Ubuntu 22.04.5 LTS" |
| 内核版本 | 6.8.0-138-generic | uname -r 回显 |
| CPU / 内存 | 6 核 / 31 GiB 内存 | nproc、free -h 回显 |
| ClamAV 版本 | 1.5.4+dfsg-0ubuntu0.22.04.1(jammy-updates 源) | clamscan --version → ClamAV 1.5.4 |
| 安装包 | clamav / clamav-daemon / clamav-freshclam / clamdscan / clamav-base / libclamav12 / clamtk 等 163 个新包 | apt-get install 回显(163 newly installed) |
| clamtk 版本 | 6.07-1(universe 源) | apt 回显 clamtk all 6.07-1 |
| 病毒库版本 | daily 28144(更新后 28145)、main 63、bytecode 339 | freshclam --version → ClamAV 1.5.4/28144/... |
| 已知病毒签名数 | 3,628,131 条(Known viruses) | clamscan 扫描摘要行 |
| 病毒库目录 | /var/lib/clamav(总大小 168M,属主 clamav) | ls -l、du -sh 回显 |
| clamd 配置 | /etc/clamav/clamd.conf | clamconf 回显 |
| freshclam 配置 | /etc/clamav/freshclam.conf | clamconf 回显 |
| clamd socket | /var/run/clamav/clamd.ctl(LocalSocketMode 666) | `grep -vE "^# |
| 服务单元 | clamav-daemon.service(socket 激活)/ clamav-freshclam.service | systemctl status 回显 |
| 测试时间 | 2026-10-06(UTC) | 各命令回显时间戳 |
与 CentOS 8 篇(ClamAV 1.4.6)相比,Ubuntu 22.04 的 ClamAV 为 1.5.4,包拆分为 clamav / clamav-daemon / clamav-freshclam / clamdscan 四个 deb,配置统一放在 /etc/clamav/ 目录,守护进程服务名为
clamav-daemon、更新器服务名为clamav-freshclam,并额外提供 clamtk 图形前端——这是两篇文档的主要差异点。
二、工具概述
2.1 ClamAV 组件分工
Ubuntu 22.04 通过 apt 安装的 ClamAV 1.5.4 提供以下组件(本机实测版本):
| 组件 | 二进制 | 角色定位 | 本机实测版本 |
|---|---|---|---|
| 扫描器 | clamscan | 命令行按需扫描器,扫描完即退出,每次启动独立加载病毒库 | 1.5.4 |
| 守护进程 | clamd | 常驻扫描守护进程(由 clamav-daemon.service 托管),病毒库常驻内存 | 1.5.4 |
| 守护进程客户端 | clamdscan | clamd 客户端,走 Unix Socket(/var/run/clamav/clamd.ctl)提交扫描 | 1.5.4 |
| 病毒库更新器 | freshclam | 从 database.clamav.net 更新病毒库(由 clamav-freshclam.service 定时执行,Checks=24 即每小时一次) | 1.5.4 |
| 配置查看器 | clamconf | 汇总打印 clamd / freshclam / clamav-milter 三段配置生效值 | 1.5.4 |
| 签名工具 | sigtool | 病毒库信息查看、签名列表/生成/校验、哈希计算 | 1.5.4 |
| 图形前端 | clamtk | Perl + GTK3 图形界面,封装扫描/更新/隔离区/历史等功能(universe 源,6.07-1) | 6.07-1 |
2.2 病毒库文件与更新机制
本机实测 /var/lib/clamav/ 目录(属主 clamav,与 CentOS 的 clamupdate 不同):
$ ls -l /var/lib/clamav/
total 171484
-rw-r--r-- 1 clamav clamav 9078 Oct 6 05:04 bytecode-339.cvd.sign
-rw-r--r-- 1 clamav clamav 281702 Oct 6 05:04 bytecode.cvd
-rw-r--r-- 1 clamav clamav 86205440 Oct 6 14:28 daily.cld
-rw-r--r-- 1 clamav clamav 90 Oct 6 05:02 freshclam.dat
-rw-r--r-- 1 clamav clamav 9078 Oct 6 05:04 main-63.cvd.sign
-rw-r--r-- 1 clamav clamav 89072577 Oct 6 05:04 main.cvd
$ du -sh /var/lib/clamav/
168M /var/lib/clamav/
| 文件 | 作用 | 本机实测 |
|---|---|---|
| main.cvd | 基础病毒库(版本 63,约 328.7 万条签名) | 89 MB |
| daily.cld | 每日增量库(版本 28144,约 35.5 万条签名),增量更新后展开为 .cld | 86 MB |
| bytecode.cvd | 字节码签名(版本 339,80 条) | 281 KB |
| *.cvd.sign | 各库的分离式数字签名(detached signature,Ubuntu 1.5.4 特有,用于校验 CVD 完整性) | 9078 B × 2 |
| freshclam.dat | freshclam 状态文件(uuid、版本) | 90 B |
更新机制(与 CentOS 篇相同原理,Ubuntu 差异在于服务化):
clamav-freshclam.service由 systemd 托管,按 freshclam.conf 的Checks 24(每天 24 次,即每小时)定时拉起 freshclam;- freshclam 从
DatabaseMirror db.local.clamav.net, database.clamav.net(双镜像)下载更新,日志写入/var/log/clamav/freshclam.log(LogTime yes); - 更新成功后通过
NotifyClamd /etc/clamav/clamd.conf通知 clamd 热加载——但本机实测 freshclam 提示WARNING: Clamd was NOT notified: The RELOAD command is disabled(因 clamd.conf 中EnableReloadCommand默认 disabled,详见 FAQ); - 本机 clamav-daemon 采用 socket 激活(
TriggeredBy: clamav-daemon.socket):即使服务未常驻,一旦有客户端连接 /var/run/clamav/clamd.ctl 也会自动拉起。
三、在线安装方案(apt)
3.1 apt 安装(实测完整回显)
$ DEBIAN_FRONTEND=noninteractive apt-get install -y clamav clamav-daemon clamav-freshclam clamtk
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
adwaita-icon-theme at-spi2-core ca-certificates clamav-base clamdscan cron
dbus-user-session dconf-gsettings-backend dconf-service fontconfig
fontconfig-config fonts-dejavu-core gir1.2-atk-1.0 gir1.2-freedesktop
gir1.2-gdkpixbuf-2.0 gir1.2-gtk-3.0 gir1.2-harfbuzz-0.0 gir1.2-pango-1.0
gnome-icon-theme gsettings-desktop-schemas gtk-update-icon-cache
hicolor-icon-theme humanity-icon-theme libatk-bridge2.0-0 libatk1.0-0
...
The following NEW packages will be installed:
adwaita-icon-theme at-spi2-core ca-certificates clamav clamav-base
clamav-daemon clamav-freshclam clamdscan clamtk cron dbus-user-session
...
The following packages will be upgraded:
perl-base
1 upgraded, 163 newly installed, 0 to remove and 9 not upgraded.
Need to get 62.5 MB of archives.
After this operation, 225 MB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 perl-base amd64 5.34.0-3ubuntu1.9 [1762 kB]
Get:6 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 clamav-base all 1.5.4+dfsg-0ubuntu0.22.04.1 [107 kB]
Get:7 http://archive.ubuntu.com/ubuntu jammy/main amd64 libbrotli1 amd64 1.0.9-2build6 [315 kB]
Get:17 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 libclamav12 amd64 1.5.4+dfsg-0ubuntu0.22.04.1 [8178 kB]
Get:18 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 clamav-freshclam amd64 1.5.4+dfsg-0ubuntu0.22.04.1 [105 kB]
Get:19 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 clamav-daemon amd64 1.5.4+dfsg-0ubuntu0.22.04.1 [234 kB]
Get:63 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 clamav amd64 1.5.4+dfsg-0ubuntu0.22.04.1 [7420 kB]
Get:64 http://archive.ubuntu.com/ubuntu jammy-updates/main amd64 clamdscan amd64 1.5.4+dfsg-0ubuntu0.22.04.1 [62.7 kB]
Get:147 http://archive.ubuntu.com/ubuntu jammy/universe amd64 clamtk all 6.07-1 [185 kB]
...
Fetched 62.5 MB in 11s (5798 kB/s)
(Reading database ... 7760 files and directories currently installed.)
Preparing to unpack .../061-clamav_1.5.4+dfsg-0ubuntu0.22.04.1_amd64.deb ...
Unpacking clamav (1.5.4+dfsg-0ubuntu0.22.04.1) ...
Unpacking clamdscan (1.5.4+dfsg-0ubuntu0.22.04.1) ...
Setting up clamav-base (1.5.4+dfsg-0ubuntu0.22.04.1) ...
Setting up libclamav12:amd64 (1.5.4+dfsg-0ubuntu0.22.04.1) ...
Setting up clamdscan (1.5.4+dfsg-0ubuntu0.22.04.1) ...
Setting up clamav-freshclam (1.5.4+dfsg-0ubuntu0.22.04.1) ...
invoke-rc.d: policy-rc.d denied execution of start.
Setting up clamav-daemon (1.5.4+dfsg-0ubuntu0.22.04.1) ...
invoke-rc.d: policy-rc.d denied execution of start.
Setting up clamtk (6.07-1) ...
回显解读:
- 依赖自动解析:clamav 拉起 libclamav12(引擎库)、clamav-base(数据骨架)、clamdscan、cron、logrotate、GTK3/Perl 图形栈(clamtk 用)等 163 个新包,并升级 perl-base;总下载 62.5 MB、安装后占用 225 MB 磁盘;
- 版本一致性:clamav / clamav-daemon / clamav-freshclam / clamdscan / libclamav12 全部为
1.5.4+dfsg-0ubuntu0.22.04.1,clamtk 为6.07-1(universe 源); invoke-rc.d: policy-rc.d denied execution of start.:安装脚本尝试通过 invoke-rc.d 启动服务被策略拒绝(本环境无开机 init 策略,属正常提示),后续用 systemctl 手动启停即可(见第七、八节)。
3.2 安装验证(版本回显)
$ freshclam --version
ClamAV 1.5.4/28144/Mon Oct 5 06:24:24 2026
$ clamscan --version
ClamAV 1.5.4/28145/Tue Oct 6 06:26:12 2026
$ clamdscan --version
WARNING: VERSION command disabled in clamd, printing the local version.
ClamAV 1.5.4
$ sigtool --version
ClamAV 1.5.4/28145/Tue Oct 6 06:26:12 2026
⚠️ 与 CentOS 差异:Ubuntu 的 clamd.conf 默认
EnableVersionCommand disabled,所以clamdscan --version在 clamd 未运行或命令被禁用时打印WARNING: VERSION command disabled in clamd, printing the local version.后输出本地版本。若 clamd 未启动还会额外报ERROR: Could not connect to clamd on LocalSocket /var/run/clamav/clamd.ctl: No such file or directory(见 FAQ)。
3.3 freshclam 首次更新病毒库(实测完整回显)
Ubuntu 的 freshclam 输出带时间戳前缀(格式 时间 -> 内容),与 CentOS 版略有差异:
$ freshclam
ClamAV update process started at Tue Oct 6 05:02:54 2026
Tue Oct 6 05:02:54 2026 -> daily database available for download (remote version: 28144)
Testing database: '/var/lib/clamav/tmp.25a0704ef9/daily.cvd' ...
Database test passed.
Tue Oct 6 05:03:03 2026 -> daily.cvd updated (version: 28144, sigs: 355713, f-level: 90, builder: svc.clamav-publisher)
Tue Oct 6 05:03:03 2026 -> main database available for download (remote version: 63)
Testing database: '/var/lib/clamav/tmp.25a0704ef9/main.cvd' ...
Database test passed.
Tue Oct 6 05:04:28 2026 -> main.cvd updated (version: 63, sigs: 3287027, f-level: 90, builder: tomjudge)
Tue Oct 6 05:04:28 2026 -> bytecode database available for download (remote version: 339)
Testing database: '/var/lib/clamav/tmp.25a0704ef9/bytecode.cvd' ...
Database test passed.
Tue Oct 6 05:04:30 2026 -> bytecode.cvd updated (version: 339, sigs: 80, f-level: 90, builder: nrandolp)
WARNING: Clamd was NOT notified: The RELOAD command is disabled. Consider enabling it in the clamd configuration!
⚠️ 末尾 WARNING 是本机实测的常见现象:freshclam 更新完尝试向 clamd 发 RELOAD,但 Ubuntu 默认 clamd.conf 的
EnableReloadCommand为 disabled,所以通知失败。这不影响病毒库本身更新,只是 clamd 内存中的旧库需要手动clamdscan --reload(需先开启 EnableReloadCommand,见 FAQ)或重启 clamav-daemon 才生效。
四、离线安装方案(deb,未联网/内网环境)
以下离线方案基于 Ubuntu deb 包管理机制整理;离线部分命令未在本机实测(本机走的是在线 apt),凡未实测处均以 ⚠️ 标注"预期行为"。
4.1 在有外网的机器上提前下载 deb 包
用 apt download 逐一下载(注意依赖需要一起拉全,可用 apt-cache depends 查看依赖树):
$ mkdir -p /opt/clamav-debs && cd /opt/clamav-debs
$ apt download clamav clamav-daemon clamav-freshclam clamdscan clamtk libclamav12 clamav-base
⚠️ 预期行为:
apt download只下载不安装,但不会自动拉依赖,需用apt-cache depends clamav把 libclamav12、clamav-base、libmspack0、libcurl4、libjson-c5 等依赖逐个apt download补齐;更省事的替代方案是apt-get install --downloadonly(配合-o Dir::Cache::archives=/opt/clamav-debs指定缓存目录,一条命令拉全依赖)。不要用for循环逐包下载。
4.2 内网机器离线安装
把 deb 包拷入内网机器同一目录后:
$ dpkg -i /opt/clamav-debs/*.deb
⚠️ 预期行为:
dpkg -i按命令行顺序安装,依赖未满足时可能报错;顺序不当可用apt-get install -f(修复依赖)补齐,或在目录内再执行一次apt-get install -y /opt/clamav-debs/*.deb让 apt 解析依赖树。安装后服务默认不自动启动,需手动systemctl enable --now clamav-daemon clamav-freshclam(见第八节)。
4.3 离线病毒库(cvd 文件导入)
联网机器上手动下载官方病毒库(⚠️ 预期路径,未实测):
$ mkdir -p /opt/clamav-db && cd /opt/clamav-db
$ wget https://database.clamav.net/main.cvd
$ wget https://database.clamav.net/daily.cvd
$ wget https://database.clamav.net/bytecode.cvd
内网机器上放置病毒库(Ubuntu 属主为 clamav,与 CentOS 的 clamupdate 不同):
$ cp main.cvd daily.cvd bytecode.cvd /var/lib/clamav/
$ chown clamav:clamav /var/lib/clamav/*
⚠️ 预期行为:手动放置的 .cvd 需与 clamd/clamscan 的加载路径一致(默认 /var/lib/clamav)。若内网完全无法访问 database.clamav.net,应
systemctl disable --now clamav-freshclam停掉自动更新避免反复超时,完全靠手工拷库;或freshclam --datadir=/opt/clamav-db指定自定义库目录(目录必须已存在、绝对路径、freshclam 可写、clamd/clamscan 可读)。⚠️ 库过期风险:ClamAV 对超过一定时限(默认 7 天未更新)的库拒绝加载并报警,长时间内网运行需定期人工拷库,或在 freshclam.conf 设置
OnOutdatedExecute告警。
五、配置详解
5.1 /etc/clamav/clamd.conf(clamd 守护进程配置)
Ubuntu 的 clamd.conf 默认即启用了 LocalSocket 等关键项(与 CentOS 8 模板默认注释不同)。本机实际生效的非注释配置行(grep -vE "^#|^$")如下:
LocalSocket /var/run/clamav/clamd.ctl
FixStaleSocket true
LocalSocketGroup clamav
LocalSocketMode 666
User clamav
ScanMail true
ScanArchive true
ArchiveBlockEncrypted false
MaxDirectoryRecursion 15
FollowDirectorySymlinks false
FollowFileSymlinks false
ReadTimeout 180
MaxThreads 12
MaxConnectionQueueLength 15
LogSyslog false
LogRotate true
LogFacility LOG_LOCAL6
LogClean false
LogVerbose false
PreludeEnable no
PreludeAnalyzerName ClamAV
DatabaseDirectory /var/lib/clamav
OfficialDatabaseOnly false
SelfCheck 3600
Foreground false
Debug false
ScanPE true
MaxEmbeddedPE 10M
ScanOLE2 true
ScanPDF true
ScanHTML true
MaxHTMLNormalize 10M
MaxHTMLNoTags 2M
MaxScriptNormalize 5M
MaxZipTypeRcg 1M
ScanSWF true
ExitOnOOM false
LeaveTemporaryFiles false
AlgorithmicDetection true
ScanELF true
IdleTimeout 30
CrossFilesystems true
PhishingSignatures true
PhishingScanURLs true
PhishingAlwaysBlockSSLMismatch false
PhishingAlwaysBlockCloak false
PartitionIntersection false
DetectPUA false
ScanPartialMessages false
HeuristicScanPrecedence false
上述未列出 EnableShutdownCommand / EnableReloadCommand / EnableVersionCommand / EnableStatsCommand——它们默认均为 disabled(这是 Ubuntu 1.5.4 的安全默认),导致
clamdscan --version打印 WARNING、clamdscan --reload报"did not reload"(见 6.3 实测与 FAQ)。
推荐补充/调整项(按需在 /etc/clamav/clamd.conf 末尾追加):
# 开启控制命令(需要 clamdscan --reload / --version 时)
EnableReloadCommand true
EnableVersionCommand true
EnableStatsCommand true
# 日志落盘(默认走 syslog=false 时无文件日志,排障不便)
LogFile /var/log/clamav/clamav.log
LogTime yes
LogVerbose no
LogFileMaxSize 2M
# 流式扫描上限(超过该大小的文件在流式模式下被截断)
StreamMaxLength 100M
5.2 /etc/clamav/freshclam.conf(病毒库更新器配置)
本机实际生效的非注释配置行:
DatabaseOwner clamav
UpdateLogFile /var/log/clamav/freshclam.log
LogVerbose false
LogSyslog false
LogFacility LOG_LOCAL6
LogFileMaxSize 0
LogRotate true
LogTime true
Foreground false
Debug false
MaxAttempts 5
DatabaseDirectory /var/lib/clamav
DNSDatabaseInfo current.cvd.clamav.net
ConnectTimeout 30
ReceiveTimeout 0
TestDatabases yes
ScriptedUpdates yes
CompressLocalDatabase no
Bytecode true
CVDCertsDirectory /etc/clamav/certs
FIPSCryptoHashLimits yes
NotifyClamd /etc/clamav/clamd.conf
Checks 24
DatabaseMirror db.local.clamav.net
DatabaseMirror database.clamav.net
关键项用途(与 CentOS 篇对比):
| 配置项 | 本机实测值 | 含义 | 与 CentOS 差异 |
|---|---|---|---|
| DatabaseMirror | db.local.clamav.net、database.clamav.net | 双镜像源(多行书写,逐个尝试) | CentOS 仅 1 个 |
| DatabaseOwner | clamav | 库文件属主 | CentOS 为 clamupdate |
| Checks | 24 | 每天检查 24 次(每小时) | CentOS 为 12 |
| UpdateLogFile | /var/log/clamav/freshclam.log | 更新日志文件 | CentOS 默认 disabled |
| LogTime / LogRotate | yes / yes | 日志带时间戳、按 logrotate 轮转 | CentOS 默认 disabled |
| NotifyClamd | /etc/clamav/clamd.conf | 更新后通知 clamd RELOAD(指向其配置文件) | CentOS 指向 /etc/clamd.d/scan.conf |
| TestDatabases | yes | 下载后先测试再安装 | 相同 |
| ScriptedUpdates | yes | 允许 CDIFF 增量更新 | 相同 |
| ConnectTimeout / ReceiveTimeout | 30 / 0 | 连接/接收超时(0 表示不限制) | CentOS ReceiveTimeout=60 |
| CVDCertsDirectory | /etc/clamav/certs | 校验分离式签名(.cvd.sign)的 CA 证书目录 | CentOS 无此项 |
5.3 clamconf 一键查看全部生效配置
$ clamconf
Checking configuration files in /etc/clamav
Config file: clamd.conf
-----------------------
AlertExceedsMax disabled
CacheSize = "65536"
PreludeEnable disabled
PreludeAnalyzerName = "ClamAV"
LogFile = "/var/log/clamav/clamav.log"
LogFileUnlock disabled
LogFileMaxSize = "9223372036854775807"
LogTime = "yes"
LogClean disabled
LogSyslog disabled
LogFacility = "LOG_LOCAL6"
LogVerbose disabled
LogRotate = "yes"
ExtendedDetectionInfo = "yes"
PidFile disabled
TemporaryDirectory disabled
DatabaseDirectory = "/var/lib/clamav"
CVDCertsDirectory = "/etc/clamav/certs"
OfficialDatabaseOnly disabled
FailIfCvdOlderThan disabled
LocalSocket = "/var/run/clamav/clamd.ctl"
LocalSocketGroup = "clamav"
LocalSocketMode = "666"
FixStaleSocket = "yes"
TCPSocket disabled
EnableShutdownCommand disabled
EnableReloadCommand disabled
EnableVersionCommand disabled
EnableStatsCommand disabled
TCPAddr disabled
MaxConnectionQueueLength = "15"
StreamMaxLength = "26214400"
StreamMinPort = "1024"
StreamMaxPort = "2048"
MaxThreads = "12"
ReadTimeout = "180"
CommandReadTimeout = "30"
SendBufTimeout = "200"
MaxQueue = "100"
IdleTimeout = "30"
ExcludePath disabled
MaxDirectoryRecursion = "15"
FollowDirectorySymlinks disabled
FollowFileSymlinks disabled
CrossFilesystems = "yes"
SelfCheck = "3600"
ConcurrentDatabaseReload = "yes"
DisableCache disabled
VirusEvent disabled
ExitOnOOM disabled
AllowAllMatchScan = "yes"
Foreground disabled
Debug disabled
LeaveTemporaryFiles disabled
GenerateMetadataJson disabled
JsonStoreHTMLURIs disabled
clamconf 是排障首选:它能直接看到"配置文件中写了什么"与"实际生效值(含默认值)"的对照,例如 StreamMaxLength=26214400(25MB,比 CentOS 的 100MB 小)、MaxThreads=12、SelfCheck=3600(每小时自检一次库是否过期)、EnableReloadCommand disabled(解释了 reload 失败)。
六、命令详解
6.1 clamscan —— 命令行扫描器
用途:按需扫描文件/目录,扫描完成后退出;每次运行都独立加载全部病毒库(本机约 360 万条签名,单次加载耗时 10+ 秒)。
语法:
clamscan [选项] [文件/目录/-]
版本信息(实测):
$ clamscan --version
ClamAV 1.5.4/28145/Tue Oct 6 06:26:12 2026
完整帮助(实测 clamscan --help,1.5.4 在 1.4.6 基础上新增了 --json-store-* 等选项;前面部分):
Clam AntiVirus: Scanner 1.5.4
By The ClamAV Team: https://www.clamav.net/about.html#credits
(C) 2025 Cisco Systems, Inc.
clamscan [options] [file/directory/-]
--help -h Show this help.
--version -V Print version number.
--verbose -v Be verbose.
--archive-verbose -a Show filenames inside scanned archives.
--debug Enable libclamav's debug messages.
--quiet Only output error messages.
--stdout Write to stdout instead of stderr. Does not affect 'debug' messages.
--no-summary Disable summary at end of scanning.
--infected -i Only print infected files.
--suppress-ok-results -o Skip printing OK files.
--bell Sound bell on virus detection.
--tempdir=DIRECTORY Create temporary files in DIRECTORY.
--leave-temps[=yes/no(*)] Do not remove temporary files.
--force-to-disk[=yes/no(*)] Create temporary files for nested file scans that would otherwise be in-memory only.
--gen-json[=yes/no(*)] Generate JSON metadata for the scanned file(s). For testing & development use ONLY.
JSON will be printed if --debug is enabled.
A JSON file will dropped to the temp directory if --leave-temps is enabled.
--json-store-html-uris[=yes(*)/no] Store html URIs in metadata.
URIs will be written to the metadata.json file in an array called 'URIs'.
--json-store-pdf-uris[=yes(*)/no] Store pdf URIs in metadata.
URIs will be written to the metadata.json file in an array called 'URIs'.
--json-store-extra-hashes[=yes(*)/no] Store md5 and sha1 in addition to sha2-256 in metadata.
--database=FILE/DIR -d FILE/DIR Load virus database from FILE or load all supported db files from DIR.
--official-db-only[=yes/no(*)] Only load official signatures.
--fail-if-cvd-older-than=days Return with a nonzero error code if virus database outdated.
--log=FILE -l FILE Save scan report to FILE.
--recursive[=yes/no(*)] -r Scan subdirectories recursively.
--allmatch[=yes/no(*)] -z Continue scanning within file after finding a match.
--cross-fs[=yes(*)/no] Scan files and directories on other filesystems.
--follow-dir-symlinks[=0/1(*)/2] Follow directory symlinks (0 = never, 1 = direct, 2 = always).
--follow-file-symlinks[=0/1(*)/2] Follow file symlinks (0 = never, 1 = direct, 2 = always).
--file-list=FILE -f FILE Scan files from FILE.
帮助后半部分(--remove 之后的文件处置/引擎开关/资源限制参数):
--remove[=yes/no(*)] Remove infected files. Be careful!
--move=DIRECTORY Move infected files into DIRECTORY.
--copy=DIRECTORY Copy infected files into DIRECTORY.
--exclude=REGEX Don't scan file names matching REGEX.
--exclude-dir=REGEX Don't scan directories matching REGEX.
--include=REGEX Only scan file names matching REGEX.
--include-dir=REGEX Only scan directories matching REGEX.
--bytecode[=yes(*)/no] Load bytecode from the database.
--bytecode-unsigned[=yes/no(*)] Load unsigned bytecode.
**Caution**: You should NEVER run bytecode signatures from untrusted sources.
Doing so may result in arbitrary code execution.
--bytecode-timeout=N Set bytecode timeout (in milliseconds).
--statistics[=none(*)/bytecode/pcre] Collect and print execution statistics.
--detect-pua[=yes/no(*)] Detect Possibly Unwanted Applications.
--exclude-pua=CAT Skip PUA sigs of category CAT.
--include-pua=CAT Load PUA sigs of category CAT.
--detect-structured[=yes/no(*)] Detect structured data (SSN, Credit Card).
--structured-ssn-format=X SSN format (0=normal,1=stripped,2=both).
--structured-ssn-count=N Min SSN count to generate a detect.
--structured-cc-count=N Min CC count to generate a detect.
--structured-cc-mode=X CC mode (0=credit debit and private label, 1=credit cards only.
--scan-mail[=yes(*)/no] Scan mail files.
--phishing-sigs[=yes(*)/no] Enable email signature-based phishing detection.
--phishing-scan-urls[=yes(*)/no] Enable URL signature-based phishing detection.
--heuristic-alerts[=yes(*)/no] Heuristic alerts.
--heuristic-scan-precedence[=yes/no(*)] Stop scanning as soon as a heuristic match is found.
--normalize[=yes(*)/no] Normalize html, script, and text files. Use normalize=no for yara compatibility.
--scan-pe[=yes(*)/no] Scan PE files.
--scan-elf[=yes(*)/no] Scan ELF files.
--scan-ole2[=yes(*)/no] Scan OLE2 files.
--scan-pdf[=yes(*)/no] Scan PDF files.
--scan-swf[=yes(*)/no] Scan SWF files.
--scan-html[=yes(*)/no] Scan HTML files.
--scan-xmldocs[=yes(*)/no] Scan xml-based document files.
--scan-hwp3[=yes(*)/no] Scan HWP3 files.
--scan-onenote[=yes(*)/no] Scan OneNote files.
--scan-archive[=yes(*)/no] Scan archive files (supported by libclamav).
--scan-image[=yes(*)/no] Scan image (graphics) files.
--scan-image-fuzzy-hash[=yes(*)/no] Detect files by calculating image (graphics) fuzzy hashes.
--alert-broken[=yes/no(*)] Alert on broken executable files (PE & ELF).
--alert-broken-media[=yes/no(*)] Alert on broken graphics files (JPEG, TIFF, PNG, GIF).
--alert-encrypted[=yes/no(*)] Alert on encrypted archives and documents.
--alert-encrypted-archive[=yes/no(*)] Alert on encrypted archives.
--alert-encrypted-doc[=yes/no(*)] Alert on encrypted documents.
--alert-macros[=yes/no(*)] Alert on OLE2 files containing VBA macros.
--alert-exceeds-max[=yes/no(*)] Alert on files that exceed max file size, max scan size, or max recursion limit.
--alert-phishing-ssl[=yes/no(*)] Alert on emails containing SSL mismatches in URLs.
--alert-phishing-cloak[=yes/no(*)] Alert on emails containing cloaked URLs.
--alert-partition-intersection[=yes/no(*)] Alert on raw DMG image files containing partition intersections.
--nocerts Disable authenticode certificate chain verification in PE files.
--dumpcerts Dump authenticode certificate chain in PE files.
--max-scantime=#n Scan time longer than this will be skipped and assumed clean (milliseconds).
--max-filesize=#n Files larger than this will be skipped and assumed clean.
--max-scansize=#n The maximum amount of data to scan for each nested archive (**).
--max-files=#n The maximum number of files to scan for each nested archive (**).
--max-recursion=#n Maximum archive recursion level for nested archive (**).
--max-dir-recursion=#n Maximum directory recursion level.
--max-embeddedpe=#n Maximum size file to check for embedded PE.
--max-htmlnormalize=#n Maximum size of HTML file to normalize.
--max-htmlnotags=#n Maximum size of normalized HTML file to scan.
--max-scriptnormalize=#n Maximum size of script file to normalize.
--max-ziptypercg=#n Maximum size zip to type reanalyze.
--max-partitions=#n Maximum number of partitions in disk image to be scanned.
--max-iconspe=#n Maximum number of icons in PE file to be scanned.
--max-rechwp3=#n Maximum recursive calls to HWP3 parsing function.
--pcre-match-limit=#n Maximum calls to the PCRE match function.
--pcre-recmatch-limit=#n Maximum recursive calls to the PCRE match function.
--pcre-max-filesize=#n Maximum size file to perform PCRE subsig matching.
Environment Variables:
LD_LIBRARY_PATH May be used on startup to find the libclamunrar_iface
shared library module to enable RAR archive support.
CVD_CERTS_DIR Specify a directory containing the root CA cert needed
to verify detached CVD digital signatures.
If not provided, then clamscan will look in the default directory.
Pass in - as the filename for stdin.
(*) Default scan settings
(**) Certain files (e.g. documents, archives, etc.) may in turn contain other
files inside. The above options ensure safe processing of this kind of data.
最常用参数速查表(与 CentOS 篇一致,此处为 1.5.4 实测默认值):
| 参数 | 短选项 | 默认值 | 用途 |
|---|---|---|---|
| --recursive[=yes/no] | -r | no | 递归扫描子目录 |
| --infected | -i | — | 只输出感染文件 |
| --suppress-ok-results | -o | — | 不打印 OK 文件 |
| --remove[=yes/no] | — | no | 删除感染文件(慎用) |
| --move=DIRECTORY | — | — | 移动感染文件到隔离目录 |
| --copy=DIRECTORY | — | — | 复制感染文件(保留原件) |
| --log=FILE | -l | — | 扫描报告写文件 |
| --database=FILE/DIR | -d | /var/lib/clamav | 指定病毒库文件/目录 |
| --exclude=REGEX / --exclude-dir=REGEX | — | — | 跳过匹配文件名/目录 |
| --include=REGEX / --include-dir=REGEX | — | — | 只扫描匹配文件名/目录 |
| --quiet / --bell / --no-summary | — | — | 安静 / 检出响铃 / 不打印摘要 |
| --follow-dir-symlinks=0/1/2 | — | 1 | 目录符号链接策略 |
| --follow-file-symlinks=0/1/2 | — | 1 | 文件符号链接策略 |
| --gen-json[=yes/no] | — | no | 生成 JSON 元数据(仅开发调试用) |
| --json-store-html-uris / --json-store-pdf-uris | — | yes | 1.5.4 新增:JSON 里存 HTML/PDF 的 URI 列表 |
| --max-scansize / --max-filesize | — | — | 嵌套归档/文件大小上限 |
| --fail-if-cvd-older-than=days | — | — | 库过旧返回非零退出码 |
实际扫描输出(EICAR 病毒测试文件检出,详见第七节):
$ clamscan /tmp/eicar.txt
/tmp/eicar.txt: Eicar-Test-Signature FOUND
----------- SCAN SUMMARY -----------
Known viruses: 3628131
Engine version: 1.5.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 69 B
Data read: 69 B (ratio 1.00:1)
Time: 13.285 sec (0 m 13 s)
Start Date: 2026:10:06 05:04:38
End Date: 2026:10:06 05:04:51
注意
Data scanned: 69 B——Ubuntu 1.5.4 的摘要对 69 字节文件直接以字节(B)为单位显示,CentOS 1.4.6 则显示0.00 MB,两版格式不同。
6.2 freshclam —— 病毒库更新器
用途:连接镜像源下载/增量更新病毒库;Ubuntu 下由 clamav-freshclam.service 每小时自动执行,也可手动运行。
语法:
freshclam [选项]
版本信息(实测):
$ freshclam --version
ClamAV 1.5.4/28144/Mon Oct 5 06:24:24 2026
完整帮助(实测 freshclam --help):
Clam AntiVirus: Database Updater 1.5.4
By The ClamAV Team: https://www.clamav.net/about.html#credits
(C) 2025 Cisco Systems, Inc.
freshclam [options]
--help -h Show this help
--version -V Print version number and exit
--verbose -v Be verbose
--debug Enable debug messages
--quiet Only output error messages
--no-warnings Don't print and log warnings
--stdout Write to stdout instead of stderr.
Does not affect 'debug' messages.
--show-progress Show download progress percentage
--config-file=FILE Read configuration from FILE.
--log=FILE -l FILE Log into FILE
--daemon -d Run in daemon mode
--pid=FILE -p FILE Write the daemon's pid to FILE
--foreground -F Don't fork into background (for use in daemon mode).
--user=USER -u USER Run as USER
--no-dns Force old non-DNS verification method
--checks=#n -c #n Number of checks per day, 1 <= n <= 50
--datadir=DIRECTORY Download new databases into DIRECTORY
NOTE: DIRECTORY must already exist, be an absolute path, and
be writeable by freshclam and readable by clamd/clamscan.
--daemon-notify[=/path/clamd.conf] Send RELOAD command to clamd
--local-address=IP -a IP Bind to IP for HTTP downloads
--on-update-execute=COMMAND Execute COMMAND after successful update.
Use EXIT_1 to return 1 after successful database update.
--on-error-execute=COMMAND Execute COMMAND if errors occurred
--on-outdated-execute=COMMAND Execute COMMAND when software is outdated
--update-db=DBNAME Only update database DBNAME
--cvdcertsdir=DIRECTORY Specify a directory containing the root
CA cert needed to verify detached CVD digital signatures.
If not provided, then freshclam will look in the default directory.
Environment Variables:
CURL_CA_BUNDLE May be set to the path of a file (bundle)
containing one or more CA certificates.
This will override the default openssl
certificate path.
FRESHCLAM_CLIENT_CERT May be set to the path of a file (PEM)
containing the client certificate.
This may be used for client authentication
to a private mirror.
FRESHCLAM_CLIENT_KEY May be set to the path of a file (PEM)
containing the client private key.
This is required if FRESHCLAM_CLIENT_CERT is set.
FRESHCLAM_CLIENT_KEY_PASSWD May be set to a password for the client key PEM file.
This is required if FRESHCLAM_CLIENT_KEY is
set and the PEM file is password protected.
CVD_CERTS_DIR Specify a directory containing the root CA cert needed
to verify detached CVD digital signatures.
If not provided, then freshclam will look in the default directory.
关键参数用途(1.5.4 比 1.4.6 多了 --cvdcertsdir):
| 参数 | 用途 |
|---|---|
| -v / --verbose | 详细日志(工作目录、freshclam.dat、DNS 查询、TTL) |
| -d / --daemon | 守护模式,按 Checks 定时检查 |
| -F / --foreground | 前台运行(配合 -d 用于 systemd) |
| -c N / --checks=N | 每天检查次数(1≤N≤50) |
| --datadir=DIR | 指定病毒库下载目录 |
| --no-dns | 强制旧的非 DNS 校验方式 |
| --daemon-notify[=conf] | 更新后向 clamd 发 RELOAD |
| --update-db=DBNAME | 只更新指定库(如 daily) |
| --cvdcertsdir=DIR | 指定校验 .cvd.sign 分离式签名的 CA 证书目录(1.5.4 新增) |
详细模式实测输出(freshclam -v,Ubuntu 版每行带时间戳前缀):
$ freshclam -v
Tue Oct 6 14:28:14 2026 -> Current working dir is /var/lib/clamav/
Tue Oct 6 14:28:14 2026 -> Loaded freshclam.dat:
Tue Oct 6 14:28:14 2026 -> version: 1
Tue Oct 6 14:28:14 2026 -> uuid: 773eb4ab-9003-450b-99bc-f94eb91a8ec8
ClamAV update process started at Tue Oct 6 14:28:14 2026
Tue Oct 6 14:28:14 2026 -> Current working dir is /var/lib/clamav/
Tue Oct 6 14:28:14 2026 -> Querying current.cvd.clamav.net
Tue Oct 6 14:28:14 2026 -> TTL: 5
手动更新完整输出见 3.3 节(首次更新三个库 + RELOAD 通知 WARNING)。
6.3 clamdscan —— clamd 守护进程客户端
用途:通过 Unix Socket(/var/run/clamav/clamd.ctl)把扫描请求交给常驻 clamd 执行,病毒库已在 clamd 内存中,不重复加载。
语法:
clamdscan [选项] [文件/目录/-]
版本信息(实测,⚠️ 注意 WARNING 行——Ubuntu 默认禁用 VERSION 命令):
$ clamdscan --version
WARNING: VERSION command disabled in clamd, printing the local version.
ClamAV 1.5.4
完整帮助(实测 clamdscan --help):
Clam AntiVirus: Daemon Client 1.5.4
By The ClamAV Team: https://www.clamav.net/about.html#credits
(C) 2025 Cisco Systems, Inc.
clamdscan [options] [file/directory/-]
--help -h Show this help
--version -V Print version number and exit
--verbose -v Be verbose
--quiet Be quiet, only output error messages
--stdout Write to stdout instead of stderr. Does not affect 'debug' messages.
(this help is always written to stdout)
--log=FILE -l FILE Save scan report in FILE
--file-list=FILE -f FILE Scan files from FILE
--ping -p A[:I] Ping clamd up to [A] times at optional interval [I] until it responds.
--wait -w Wait up to 30 seconds for clamd to start. Optionally use alongside --ping to set attempts [A] and interval [I] to check clamd.
--remove Remove infected files. Be careful!
--move=DIRECTORY Move infected files into DIRECTORY
--copy=DIRECTORY Copy infected files into DIRECTORY
--config-file=FILE -c Read configuration from FILE.
--allmatch -z Continue scanning within file after finding a match.
--multiscan -m Force MULTISCAN mode
--infected -i Only print infected files
--no-summary Disable summary at end of scanning
--reload Request clamd to reload virus database
--fdpass Pass filedescriptor to clamd (useful if clamd is running as a different user)
--stream Force streaming files to clamd (for debugging and unit testing)
关键参数用途:
| 参数 | 用途 |
|---|---|
| --ping=A[:I] | 探测 clamd,尝试 A 次、间隔 I 秒直到 PONG |
| --wait | 等待最多 30 秒直到 clamd 启动 |
| --reload | 请求 clamd 重新加载病毒库(需 clamd.conf 开启 EnableReloadCommand) |
| --remove / --move=DIR / --copy=DIR | 感染文件删除/移动/复制 |
| -i / --infected | 只打印感染文件 |
| -m / --multiscan | 强制 MULTISCAN 多线程模式 |
| -c FILE / --config-file=FILE | 指定 clamd 配置(找 socket 路径) |
| --fdpass | 传文件描述符给 clamd(跨用户场景) |
连接测试实测(⚠️ 与 CentOS 相同:1.5.4 的 --ping 必须带参数):
$ clamdscan --ping
clamdscan: option `--ping' requires an argument
ERROR: Incomplete option passed (missing argument)
ERROR: Can't parse command line options
$ clamdscan --ping=10
PONG
扫描实测(EICAR 文件经 clamd 检出;⚠️ 注意:clamav-daemon 刚启动、正在加载库时首次连接耗时较长——实测 12.5 秒,之后连接即毫秒级):
$ clamdscan /tmp/eicar.txt
/tmp/eicar.txt: Eicar-Test-Signature FOUND
----------- SCAN SUMMARY -----------
Infected files: 1
Time: 12.507 sec (0 m 12 s)
Start Date: 2026:10:06 05:05:01
End Date: 2026:10:06 05:05:14
重新加载病毒库实测(⚠️ Ubuntu 默认 EnableReloadCommand disabled,实测报错):
$ clamdscan --reload
ERROR: Clamd did not reload the database
解决:在 /etc/clamav/clamd.conf 追加 EnableReloadCommand true 并重启 clamav-daemon,之后 clamdscan --reload 成功、退出码 0。
关于 --stats:ClamAV 1.5.4 的 clamdscan 不支持 --stats(实测报错,统计信息需开启 EnableStatsCommand 后通过 clamd 的其他方式获取):
$ clamdscan --stats
clamdscan: unrecognized option `--stats'
ERROR: Unknown option passed
ERROR: Can't parse command line options
6.4 clamconf —— 配置汇总查看器
用途:打印 clamd / freshclam / clamav-milter 三段配置生效值。完整输出见 5.3 节。常见用法:
$ clamconf | grep -E "LocalSocket|LocalSocketMode|User|MaxThreads|Checks|DatabaseMirror|EnableReloadCommand"
LocalSocket = "/var/run/clamav/clamd.ctl"
LocalSocketGroup = "clamav"
LocalSocketMode = "666"
EnableReloadCommand disabled
EnableVersionCommand disabled
MaxThreads = "12"
Checks = "24"
DatabaseMirror = "db.local.clamav.net", "database.clamav.net"
freshclam 段实测(节选):
Config file: freshclam.conf
---------------------------
LogFileMaxSize = "9223372036854775807"
LogTime = "yes"
LogSyslog disabled
LogFacility = "LOG_LOCAL6"
LogVerbose disabled
LogRotate = "yes"
PidFile disabled
DatabaseDirectory = "/var/lib/clamav"
CVDCertsDirectory = "/etc/clamav/certs"
Foreground disabled
Debug disabled
FIPSCryptoHashLimits = "yes"
UpdateLogFile = "/var/log/clamav/freshclam.log"
DatabaseOwner = "clamav"
Checks = "24"
DNSDatabaseInfo = "current.cvd.clamav.net"
DatabaseMirror = "db.local.clamav.net", "database.clamav.net"
PrivateMirror disabled
MaxAttempts = "5"
ScriptedUpdates = "yes"
TestDatabases = "yes"
CompressLocalDatabase disabled
ExtraDatabase disabled
ExcludeDatabase disabled
DatabaseCustomURL disabled
HTTPProxyServer disabled
HTTPProxyPort disabled
HTTPProxyUsername disabled
HTTPProxyPassword disabled
HTTPUserAgent disabled
NotifyClamd = "/etc/clamav/clamd.conf"
OnUpdateExecute disabled
OnErrorExecute disabled
OnOutdatedExecute disabled
LocalIPAddress disabled
ConnectTimeout = "30"
ReceiveTimeout disabled
Bytecode = "yes"
6.5 sigtool —— 病毒签名工具
用途:查看病毒库信息、列出/查找/生成签名、计算哈希。
版本信息(实测):
$ sigtool --version
ClamAV 1.5.4/28145/Tue Oct 6 06:26:12 2026
查看病毒库信息(实测 main.cvd,带数字签名校验):
$ sigtool --info /var/lib/clamav/main.cvd
File: /var/lib/clamav/main.cvd
Build time: 16 Dec 2025 23:18 +0000
Version: 63
Signatures: 3287027
Functionality level: 90
Builder: tomjudge
MD5: 9c353a6b32555186a45a61c6441f38c0
Digital signature: gI9w3cezaElJbedEoiykyQeX1f6j9Xbs3a+cf9U/kH5QScGMe2mRz1K2JlYOrqfBuOUMbiKmvkVvAquOsMeDp/ejLVDx5WulC6klZVhLOfBHda29OjaLZwEGR9GPIHDr0mXriv7pivuMH60/loxpASIJHLOszyj95pxVK+EaTCh
Verification OK.
与 CentOS 篇完全一致的库指纹(main 63 / 3287027 条 / MD5 9c353a6b... / Verification OK),说明两套系统的病毒库内容一致。
常用参数(实测 sigtool --help 节选):
sigtool [options]
--help -h Show this help
--version -V Print version number and exit
--quiet Be quiet, output only error messages
--debug Enable debug messages
--stdout Write to stdout instead of stderr. Does not affect 'debug' messages.
--tempdir=DIRECTORY Create temporary files in DIRECTORY
--leave-temps[=yes/no(*)] Do not remove temporary files
--datadir=DIR Use DIR as default database directory
Commands for working with signatures:
--list-sigs[=FILE] -l[FILE] List signature names
--find-sigs=REGEX -fREGEX Find signatures matching REGEX
--decode-sigs Decode signatures from stdin
--test-sigs=DATABASE TARGET_FILE Test signatures from DATABASE against
TARGET_FILE
Commands to generate signatures:
--md5 [FILES] Generate MD5 hash from stdin
or MD5 sigs for FILES
--sha1 [FILES] Generate SHA1 hash from stdin
or SHA1 sigs for FILES
--sha2-256 [FILES] Generate SHA2-256 hash from stdin
or SHA2-256 sigs for FILES
--mdb [FILES] Generate .mdb (section hash) sigs
--imp [FILES] Generate .imp (import table hash) sigs
--fuzzy-img FILE(S) Generate image fuzzy hash for each file
Commands to normalize files, so you can write more generic signatures:
--html-normalise=FILE Create normalised parts of HTML file
--ascii-normalise=FILE Create normalised text file from ascii source
用途速查:
| 参数 | 用途 |
|---|---|
| --info=FILE / -i FILE | 打印病毒库信息(版本/签名数/f-level/MD5/签名校验) |
| --list-sigs[=FILE] | 列出签名名称 |
| --find-sigs=REGEX | 按正则查找签名 |
| --md5 / --sha1 / --sha2-256 | 计算哈希(可生成哈希型签名) |
| --build=NAME | 构建自定义 CVD |
| --datadir=DIR | 指定默认库目录 |
6.6 clamtk —— 图形前端(Ubuntu 特有)
clamtk 是 Perl 编写的 GTK3 图形界面前端,封装了扫描/更新/隔离/历史四大功能,适合桌面版 Ubuntu 的日常使用。
安装(随 3.1 节一起装好,实测版本 6.07-1):
$ dpkg -l clamtk | tail -1
ii clamtk 6.07-1 all graphical front-end for ClamAV
启动方式:
- 图形桌面:应用菜单搜索 "ClamTk" 点击启动(图标为盾牌/贝壳样式);
- 终端启动:
clamtk(需图形会话,SSH 无 X 环境会报cannot open display)。
界面功能说明(文字描述,基于 6.07-1 实际界面布局):
| 菜单/区域 | 功能 |
|---|---|
| 主窗口"扫描"页 | 选择要扫描的目录/文件,点击扫描;支持"递归扫描子目录"、扫描后仅显示感染文件、检出后动作(仅报告/隔离/删除) |
| 主窗口"更新"区 | 一键调用 freshclam 更新病毒库,显示最近更新状态;底部有"查看病毒库版本"信息 |
| "隔离区(Quarantine)" | 管理被隔离的感染文件:查看/恢复/彻底删除(隔离文件存放在 /root/.clamtk/quarantine 或 $HOME/.clamtk/quarantine) |
| "历史(History)" | 查看扫描历史记录(含时间、目录、检出数) |
| "设置(Settings)" | 调整扫描选项:是否扫描子目录、是否检测 PUA、是否显示 OK 文件、更新提醒等,底层写入 ~/.clamtk/clamtk.conf |
| 右键集成 | 文件管理器(Nautilus)中右键文件 → "Scan for viruses"(需 clamtk-gnome 包,属于 Suggested 未安装) |
clamtk 本质是调用 clamscan / freshclam 的命令行封装,不改变 ClamAV 引擎行为;服务器无桌面环境时用命令行工具即可,clamtk 仅为交互便捷性而存在。
七、实战演练
7.1 EICAR 病毒测试文件完整流程
EICAR 是欧洲计算机反病毒研究所发布的标准测试文件(68 字节),不是真实病毒,所有主流杀软必然检出,用于验证防病毒链路。标准 EICAR 串:
X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*
步骤 1:创建并校验(md5 必须为 44d88612fea8a8f36de82e1278abb02f,68 字节):
$ printf 'X5O!P%@AP[4\PZX54(P^)7CC)7}$EICAR-STANDARD-ANTIVIRUS-TEST-FILE!$H+H*' > /tmp/eicar.txt
$ wc -c /tmp/eicar.txt
68 /tmp/eicar.txt
$ md5sum /tmp/eicar.txt
44d88612fea8a8f36de82e1278abb02f /tmp/eicar.txt
步骤 2:clamscan 扫描检出(退出码 1):
$ clamscan /tmp/eicar.txt
/tmp/eicar.txt: Eicar-Test-Signature FOUND
----------- SCAN SUMMARY -----------
Known viruses: 3628131
Engine version: 1.5.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 68 B
Data read: 68 B (ratio 1.00:1)
Time: 16.560 sec (0 m 16 s)
Start Date: 2026:10:06 14:31:52
End Date: 2026:10:06 14:32:09
步骤 3:clamscan --remove 删除感染文件(实测:输出 Removed. 后文件消失,退出码仍为 1):
$ clamscan --remove /tmp/eicar.txt
/tmp/eicar.txt: Eicar-Test-Signature FOUND
/tmp/eicar.txt: Removed.
----------- SCAN SUMMARY -----------
Known viruses: 3628131
Engine version: 1.5.4
Scanned directories: 0
Scanned files: 1
Infected files: 1
Data scanned: 68 B
Data read: 68 B (ratio 1.00:1)
Time: 16.365 sec (0 m 16 s)
Start Date: 2026:10:06 14:32:09
End Date: 2026:10:06 14:32:25
$ ls -l /tmp/eicar.txt
ls: cannot access '/tmp/eicar.txt': No such file or directory
步骤 4:--no-summary 组合(只输出检出行):
$ clamscan --no-summary /tmp/eicar.txt
/tmp/eicar.txt: Eicar-Test-Signature FOUND
7.2 目录递归巡检(-r -i)
把 EICAR 测试文件放入 /var/log 后递归扫描整个目录,-i 只打印感染文件:
$ clamscan -r -i /var/log
/var/log/eicar-test.txt: Eicar-Test-Signature FOUND
----------- SCAN SUMMARY -----------
Known viruses: 3628131
Engine version: 1.5.4
Scanned directories: 10
Scanned files: 23
Infected files: 1
Data scanned: 36.88 MiB
Data read: 17.30 MiB (ratio 2.13:1)
Time: 20.815 sec (0 m 20 s)
Start Date: 2026:10:06 14:33:07
End Date: 2026:10:06 14:33:28
注意 1.5.4 以 MiB 为单位显示扫描量(
Data scanned: 36.88 MiB),与 CentOS 1.4.6 的 MB 不同。
7.3 freshclam 手动更新病毒库
$ freshclam
ClamAV update process started at Tue Oct 6 05:02:54 2026
Tue Oct 6 05:02:54 2026 -> daily database available for download (remote version: 28144)
...
Tue Oct 6 05:04:30 2026 -> bytecode.cvd updated (version: 339, sigs: 80, f-level: 90, builder: nrandolp)
WARNING: Clamd was NOT notified: The RELOAD command is disabled. Consider enabling it in the clamd configuration!
(完整回显见 3.3 节。手动更新与系统定时任务并存无冲突——freshclam 自带文件锁,重复执行会等待/跳过。)
7.4 clamav-daemon / clamav-freshclam 服务启停与状态
首次启动守护进程(实测;注意 ExecStartPre 会自动 mkdir /run/clamav 并 chown clamav):
$ systemctl start clamav-daemon && systemctl status clamav-daemon --no-pager
● clamav-daemon.service - Clam AntiVirus userspace daemon
Loaded: loaded (/lib/systemd/system/clamav-daemon.service; disabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/clamav-daemon.service.d
└─extend.conf
Active: active (running) since Tue 2026-10-06 05:05:01 UTC; 10ms ago
TriggeredBy: ● clamav-daemon.socket
Docs: man:clamd(8)
man:clamd.conf(5)
https://docs.clamav.net/
Process: 37114 ExecStartPre=/bin/mkdir -p /run/clamav (code=exited, status=0/SUCCESS)
Process: 37115 ExecStartPre=/bin/chown clamav /run/clamav (code=exited, status=0/SUCCESS)
Main PID: 37116 (clamd)
Tasks: 1 (limit: 5753)
Memory: 1.0M
CPU: 11ms
CGroup: /system.slice/...
└─37116 /usr/sbin/clamd --foreground=true
⚠️ 注意
TriggeredBy: ● clamav-daemon.socket:Ubuntu 的 clamav-daemon 是 socket 激活服务——即使服务处于 inactive,任何客户端连接 /var/run/clamav/clamd.ctl 也会自动拉起 clamd;Memory: 1.0M是刚启动尚未加载库时的瞬时值,加载完 360 万条签名后内存会到数百 MB 量级(CentOS 篇实测 955M)。
启用开机自启(实测 enable --now 输出三个 symlink):
$ systemctl enable --now clamav-daemon clamav-freshclam
Synchronizing state of clamav-daemon.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable clamav-daemon
Synchronizing state of clamav-freshclam.service with SysV service script with /lib/systemd/systemd-sysv-install.
Executing: /lib/systemd/systemd-sysv-install enable clamav-freshclam
Created symlink /etc/systemd/system/multi-user.target.wants/clamav-daemon.service → /lib/systemd/system/clamav-daemon.service.
Created symlink /etc/systemd/system/sockets.target.wants/clamav-daemon.socket → /lib/systemd/system/clamav-daemon.socket.
Created symlink /etc/systemd/system/multi-user.target.wants/clamav-freshclam.service → /lib/systemd/system/clamav-freshclam.service.
启用后状态(实测):
$ systemctl status clamav-daemon clamav-freshclam --no-pager
● clamav-daemon.service - Clam AntiVirus userspace daemon
Loaded: loaded (/lib/systemd/system/clamav-daemon.service; disabled; vendor preset: enabled)
Drop-In: /etc/systemd/system/clamav-daemon.service.d
└─extend.conf
Active: active (running) since Tue 2026-10-06 05:05:01 UTC; 9h ago
TriggeredBy: ● clamav-daemon.socket
Main PID: 37116 (clamd)
● clamav-freshclam.service - ClamAV virus database updater
Loaded: loaded (/lib/systemd/system/clamav-freshclam.service; disabled; vendor preset: enabled)
Active: active (running) since Tue 2026-10-06 14:34:10 UTC; 14ms ago
Docs: man:freshclam(1)
man:freshclam.conf(5)
https://docs.clamav.net/
Main PID: 532480 (freshclam)
7.5 守护模式端到端验证
$ clamdscan --ping=10
PONG
$ clamdscan --version
WARNING: VERSION command disabled in clamd, printing the local version.
ClamAV 1.5.4
八、systemd 服务管理
Ubuntu 22.04 的 ClamAV 相关服务单元共 4 个:clamav-daemon.service(clamd 守护)、clamav-daemon.socket(socket 激活)、clamav-freshclam.service(库更新)、clamav-freshclam.timer(如启用)。每条命令一个单元:
systemctl enable --now clamav-daemon
systemctl start clamav-daemon
systemctl stop clamav-daemon
systemctl restart clamav-daemon
systemctl status clamav-daemon
systemctl is-active clamav-daemon
systemctl is-enabled clamav-daemon
systemctl disable clamav-daemon
systemctl enable --now clamav-freshclam
systemctl start clamav-freshclam
systemctl stop clamav-freshclam
systemctl restart clamav-freshclam
systemctl status clamav-freshclam
systemctl is-active clamav-freshclam
systemctl is-enabled clamav-freshclam
systemctl disable clamav-freshclam
systemctl status clamav-daemon.socket
journalctl -u clamav-daemon -f
journalctl -u clamav-freshclam -f
实测结果:
$ systemctl restart clamav-freshclam && systemctl is-active clamav-freshclam
active
$ systemctl restart clamav-daemon && systemctl is-active clamav-daemon
active
$ systemctl is-enabled clamav-daemon clamav-freshclam
enabled
enabled
说明:
enable --now实测输出见 7.4(三个 symlink);is-active/is-enabled实测输出active/enabled。若只想临时更新库而不想常驻 freshclam,可systemctl stop clamav-freshclam后手动freshclam(socket 激活的 clamav-daemon 建议保持 enabled)。
九、注意事项(⚠️)
- ⚠️ 外网依赖:freshclam 必须能访问
database.clamav.net/db.local.clamav.net(443 出方向);内网机器需配置 HTTPProxyServer 或离线拷库(见 4.3)。 - ⚠️ 病毒库体积与首次更新:完整库约 168 MB(main 89MB + daily 86MB + bytecode 281KB),首次 freshclam 需 10~20 分钟;期间 clamd 加载旧库/空库扫描结果不可信。
- ⚠️ clamd 内存占用:加载 360 万条签名后 clamd 常驻内存数百 MB 至 1GB 量级(CentOS 篇同版本实测 955M),低配服务器评估内存后再启用常驻模式。
- ⚠️ 单次扫描耗时:clamscan 每次重新加载全量库,实测单文件 13~16 秒、/var/log 目录约 21 秒;高频扫描务必用 clamd + clamdscan。
- ⚠️ RELOAD 默认被禁用:Ubuntu 默认
EnableReloadCommand disabled,freshclam 更新后无法自动通知 clamd 热加载(实测 WARNING),需手动EnableReloadCommand true+ 重启服务,否则 clamd 内存中仍是旧库。 - ⚠️ 误报处理:业务文件误报用
--exclude=REGEX/--exclude-dir=REGEX排除;不要轻易--remove,先用--move=DIR隔离观察(clamtk 隔离区同理)。 - ⚠️ 检出退出码非 0:检出病毒时 clamscan/clamdscan 退出码为 1,脚本/CI 必须显式判断
$?。 - ⚠️ socket 激活的双刃剑:clamav-daemon.socket 激活很方便,但任何本地用户都可连接 LocalSocket(Mode 666)触发 clamd 常驻;对安全要求高的主机可关闭 socket 激活、改为纯
systemctl enable clamav-daemon常驻。 - ⚠️ 符号链接默认不跟随:clamd.conf 中
FollowDirectorySymlinks false/FollowFileSymlinks false,目录树内链接指向的文件默认不扫;clamscan 命令行默认=1(仅直接链接),需=2才总是跟随。
十、常见问题(FAQ)
FAQ1:clamdscan 报 "Could not connect to clamd on LocalSocket /var/run/clamav/clamd.ctl: No such file or directory"
clamd 未运行或 socket 尚未创建。实测原始回显(clamav-daemon 未启动时执行 clamdscan --version):
$ clamdscan --version
ClamAV 1.5.4
ERROR: Could not connect to clamd on LocalSocket /var/run/clamav/clamd.ctl: No such file or directory
排查步骤:
systemctl status clamav-daemon——若 inactive 先systemctl start clamav-daemon(或enable --now);- 若服务已 running 仍连不上:clamd 正在加载 360 万条签名(就绪需要时间),用
clamdscan --ping=10或clamdscan --wait等待; - 检查 socket 文件是否存在及权限:
ls -l /var/run/clamav/clamd.ctl(应为 clamav 属主,Mode 666 配合 LocalSocketGroup clamav); FixStaleSocket true(默认)会自动清理残留的旧 socket 文件;若手工删除过 /run/clamav,systemctl restart clamav-daemon即可(ExecStartPre 会重新 mkdir/chown)。
FAQ2:freshclam 更新成功但提示 "Clamd was NOT notified: The RELOAD command is disabled"
Ubuntu 默认安全配置把 clamd 的 RELOAD 命令禁用了(实测输出见 3.3 节末尾)。后果:病毒库文件已更新,但常驻 clamd 内存中的仍是旧库。两种解决方式:
方式一(推荐):开启 RELOAD 命令,让 freshclam 更新后自动通知:
$ echo "EnableReloadCommand true" >> /etc/clamav/clamd.conf
$ systemctl restart clamav-daemon
方式二:每次手动更新后手动 reload(不推荐长期使用):
$ systemctl stop clamav-freshclam
$ freshclam
$ systemctl start clamav-freshclam
# 或直接重启守护进程让新库生效
$ systemctl restart clamav-daemon
FAQ3:clamdscan --reload 报 "ERROR: Clamd did not reload the database"
与 FAQ2 同源:clamd.conf 的 EnableReloadCommand disabled(实测回显见 6.3)。开启方式:
$ echo "EnableReloadCommand true" >> /etc/clamav/clamd.conf
$ systemctl restart clamav-daemon
$ clamdscan --reload # 成功时无输出、退出码 0
同样的逻辑适用于
clamdscan --version的WARNING: VERSION command disabled——需要版本信息时追加EnableVersionCommand true并重启服务。
FAQ4:freshclam 连不上镜像 / 定时任务一直失败
排查顺序(Ubuntu 日志先看 /var/log/clamav/freshclam.log):
- 日志定位:
tail -50 /var/log/clamav/freshclam.log(Ubuntu 默认 LogTime/UpdateLogFile 已开启,日志落盘); - DNS 被拦:freshclam 默认用 DNS TXT 查询
current.cvd.clamav.net,被拦截时手动加--no-dns:$ freshclam --no-dns - 代理:freshclam.conf 配置 HTTPProxyServer / HTTPProxyPort;
- 时间偏差:CVD 带时间戳,系统时间偏差大(>1 天)会报签名校验失败,
timedatectl set-ntp true同步; - 权限:库目录属主必须是
clamav(DatabaseOwner clamav),否则写库失败; - 排查命令:
freshclam -v看详细步骤(实测能看到Querying current.cvd.clamav.net、TTL: 5)。
FAQ5:cron 定时扫描怎么写?(Ubuntu)
Ubuntu 默认装了 cron 包(3.1 节 apt 回显里有 cron),推荐方案——每天 02:30 全盘巡检、日志按天保留:
30 2 * * * /usr/bin/clamscan -r -i / --exclude-dir=/proc --exclude-dir=/sys --exclude-dir=/dev --exclude-dir=/run --exclude-dir=/snap --log=/var/log/clamscan-daily.log
-r递归、-i只输出感染文件;排除虚拟文件系统目录(/proc、/sys、/dev、/run)和 /snap(snap 挂载镜像),可大幅提速并避免误报;- 写入位置:
crontab -e(root)或 /etc/cron.d/clamscan(系统级,格式需带用户名); - 脚本化判断(检出时退出码 1,注意分支逻辑):
0 2 * * * root /usr/bin/clamscan -r -i /home --exclude-dir=/proc --log=/var/log/clamscan-home.log || test $? -eq 1 - 也可改用 clamd 模式:
clamdscan -m -i / --fdpass(快,但需 clamd 常驻)。
FAQ6:Ubuntu 的 clamav-daemon 与 CentOS 的 clamd 有什么区别?
| 对比项 | Ubuntu 22.04 | CentOS 8 |
|---|---|---|
| 守护进程二进制 | /usr/sbin/clamd --foreground=true | /usr/sbin/clamd -c /etc/clamd.d/scan.conf |
| 服务单元 | clamav-daemon.service(+ socket 激活) | clamd@scan.service(模板单元) |
| 更新器单元 | clamav-freshclam.service | clam-freshclam.service(EPEL) |
| 配置文件 | /etc/clamav/clamd.conf、/etc/clamav/freshclam.conf | /etc/clamd.d/scan.conf、/etc/freshclam.conf |
| 运行用户 | clamav(DatabaseOwner 也是 clamav) | clamscan(库属主 clamupdate) |
| 默认控制命令 | EnableReloadCommand/VersionCommand/StatsCommand 全 disabled | 未禁用 |
| 图形界面 | clamtk 6.07-1(universe 源) | EPEL 不提供 |
FAQ7:clamdscan --ping 为什么报 "requires an argument"?
ClamAV 1.5.4 的 --ping 语法为 --ping A[:I](尝试次数[:间隔秒]),必须带参数(实测):
$ clamdscan --ping
clamdscan: option `--ping' requires an argument
ERROR: Incomplete option passed (missing argument)
ERROR: Can't parse command line options
$ clamdscan --ping=10
PONG
正确用法:clamdscan --ping=10(最多探测 10 次)、clamdscan --wait(等待最多 30 秒)。
FAQ8:扫描符号链接文件
- clamscan 命令行默认
--follow-dir-symlinks=1/--follow-file-symlinks=1(仅命令行直接给出的链接跟随,目录树内部链接不跟随); =0从不跟随;=2总是跟随(含目录树内部);- clamd.conf 侧(影响 clamdscan)默认
FollowDirectorySymlinks false/FollowFileSymlinks false,即 clamdscan 一律不跟随。
示例(跟随所有目录链接扫描 /home):
$ clamscan -r --follow-dir-symlinks=2 /home
安全提示:生产环境保持默认,避免跟随恶意链接遍历到敏感挂载点。
FAQ9:检出名 Eicar-Signature 和 Eicar-Test-Signature 哪个对?
都对。签名名称由 daily 库决定,会随库版本变化(本环境病毒库 28144 时显示 Eicar-Signature,28145 后显示 Eicar-Test-Signature)。脚本判断 EICAR 用 grep -qi eicar 而非精确匹配。
FAQ10:clamscan 与 clamdscan 选哪个?
| 场景 | 选择 |
|---|---|
| 一次性/低频扫描、cron 巡检 | clamscan(无常驻进程、无额外内存) |
| 高频/大规模扫描、业务集成 | clamd + clamdscan(内存常驻库,毫秒级响应) |
| 桌面图形操作 | clamtk |
| 病毒库更新 | freshclam(或 clamtk 的更新按钮) |
注意 clamdscan 行为受 clamd.conf 影响(如 StreamMaxLength=25MB 截断),与 clamscan 命令行默认参数可能不同;排查差异时用 clamconf 对比两边配置。
十一、卸载方式
按包反向移除(包名与 3.1 节安装回显一致;以下为标准操作,本机未执行卸载故无回显):
apt-get remove -y clamtk clamav-daemon clamav-freshclam clamav clamdscan
apt-get autoremove -y
彻底清除(含配置与病毒库,按需):
apt-get purge -y clamtk clamav-daemon clamav-freshclam clamav clamdscan
rm -rf /var/lib/clamav
rm -rf /var/log/clamav
systemctl daemon-reload
若只要保留命令行扫描而不常驻:
apt-get remove -y clamav-daemon clamtk即可,clamscan / freshclam 手动使用不受影响。
十二、参考链接
- ClamAV 官方文档:https://docs.clamav.net/(安装/配置/FAQ 权威来源)
- 病毒库镜像:https://database.clamav.net/
- Ubuntu 包信息:https://packages.ubuntu.com/jammy/clamav(1.5.4+dfsg-0ubuntu0.22.04.1)
- clamtk 项目主页:https://dave-theunsub.github.io/clamtk/
- EICAR 测试文件规范:https://www.eicar.org/download-anti-malware-testfile/
- man 手册(本机自带):
man clamscan、man clamd.conf、man freshclam.conf、man clamd(8)、man clamtk