Ubuntu 22.04 Lynis 安全审计工具部署与命令详解
Ubuntu 22.04 系统 Lynis 安全审计工具的安装(在线 apt 与离线 deb)与 lynis 全部常用命令参数实测详解,含审计报告解读、加固建议与自动审计配置
Ubuntu 22.04 Lynis 安全审计工具部署与命令详解
目标:掌握 Ubuntu 22.04 下 Lynis(v3.0.7)安全审计工具的原理、在线/离线安装、全部常用命令与参数实测、审计报告解读、加固实战与定时自动审计配置。本文全部命令回显已在 Ubuntu 22.04 真实环境实测通过
一、环境信息
本文所有命令均在一套 Ubuntu 22.04.5 LTS 最小化安装系统(systemd 托管,apt 包管理器) 上真实执行,关键环境参数如下:
| 项目 | 版本 / 值 | 实测依据 |
|---|---|---|
| 操作系统 | Ubuntu 22.04.5 LTS(jammy) | lynis-report.dat 中 os_fullname=Ubuntu 22.04.5 LTS |
| 内核版本 | 6.8.0(x86_64) | lynis audit system 初始信息 Kernel version: 6.8.0 |
| Lynis 版本 | 3.0.7-1(apt 官方源 universe 组件) | lynis --version → 3.0.7 |
| 主机名 | b3d88cde7ef0 | lynis 报告头部 Hostname: |
| 配置文件 | /etc/lynis/default.prf、/etc/lynis/custom.prf | Profiles: 行 |
| 日志文件 | /var/log/lynis.log | Log file: 行 |
| 报告文件 | /var/log/lynis-report.dat | Report file: 行 |
| 插件目录 | /etc/lynis/plugins | Plugin directory: 行 |
| 服务管理器 | systemd | Service Manager [ systemd ] |
| 内置插件 | debian 插件(Debian Tests 分类) | Plugins enabled : 1、[+] Debian Tests |
| 审计基线 | 首次完整审计 Hardening index 62、Tests performed 242 | lynis audit system 结尾 Summary |
说明:Ubuntu 22.04 的 lynis 包来自
universe组件,安装时还会带入menu依赖包;apt 包自带 systemd 定时器单元(lynis.service+lynis.timer),安装回显中可见Created symlink /etc/systemd/system/timers.target.wants/lynis.timer,但默认不会自动启动(见第八章)。
二、工具概述
2.1 Lynis 是什么
Lynis 是 CISOfy 公司开源的一款 UNIX/Linux 系统安全审计与加固工具(也支持 macOS、BSD),纯 Shell 编写、无编译依赖,以 root 权限运行后会对系统进行数百项安全检测,最终给出:
- Hardening index(加固指数):0~100 的整数分数,越高代表系统越安全;
- Warnings(警告):必须关注的高风险问题;
- Suggestions(建议):可选的加固措施;
- 一份机器可读的
lynis-report.dat报告与详细的lynis.log日志。
Lynis 的检测覆盖 CIS(Center for Internet Security)等合规基准,是等保自查、基线核查、漏洞评估场景下常用的免费工具。商业版本(Lynis Enterprise)额外提供集中管理、合规报表与持续监控能力。
2.2 工作原理
Lynis 的审计流程是三步走:
收集系统信息 → 逐项执行 tests 检测 → 汇总打分并输出报告
(osdetection) (include/tests_*.sh) (Hardening index / report.dat)
- 收集系统信息:启动时先做 OS 探测(
Detecting OS)、profile 检查(Checking profiles)、可用工具扫描(Scanning available tools),并打印程序版本、系统信息、配置文件路径等; - 逐项 tests 检测:按 categories(大类) 与 groups(分组) 组织数百个测试脚本,例如
Kernel、Users, Groups and Authentication、SSH Support、File systems、Firewalls等,每个检测点是一个带编号的 TEST(如SSH-7408、DEB-0280),检测结果分为[ OK ]、[ FOUND ]、[ SUGGESTION ]、[ WARNING ]、[ DISABLED ]、[ NOT FOUND ]等; - 汇总打分:全部 tests 结束后计算 Hardening index,把 Warnings / Suggestions 汇总列出,并把结构化数据写入
lynis-report.dat、详细信息写入lynis.log。
2.3 categories 与 tests 概念
- category(大类):3 个顶层分类
performance/privacy/security(lynis show categories实测输出); - group(分组):40 个检测分组,如
kernel、ssh、firewalls、authentication、file_permissions等(lynis show groups实测输出); - test(测试项):每个分组下有若干带唯一编号的测试,编号格式
ABC-1234(前缀=分组缩写,后缀=序号),如AUTH-9286(用户密码老化)、DEB-0810(apt-listbugs 安装检查)、SSH-7408(SSH 加固)。
Ubuntu 的 lynis 包额外带 debian 插件(/etc/lynis/plugins/plugin_debian_phase1),会多出一个 [+] Debian Tests 分类,专门检查 Debian/Ubuntu 特有项(libpam-tmpdir、apt-listbugs、needrestart、fail2ban 等),这也是 Ubuntu 上 Plugins enabled: 1、Tests performed 达 242 项(多于 CentOS 8 的 236 项)的原因。
三、在线安装方案
3.1 apt 安装
Ubuntu 官方源(universe 组件)已包含 lynis 包,直接安装即可:
DEBIAN_FRONTEND=noninteractive apt-get install -y lynis
真实回显(实测):
$ DEBIAN_FRONTEND=noninteractive apt-get install -y lynis
Reading package lists...
Building dependency tree...
Reading state information...
The following additional packages will be installed:
menu
Suggested packages:
dnsutils apt-listbugs debsecan debsums tripwire samhain aide menu-l10n gksu
| kde-runtime | ktsuss
The following NEW packages will be installed:
lynis menu
0 upgraded, 2 newly installed, 0 to remove and 10 not upgraded.
Need to get 581 kB of archives.
After this operation, 3164 kB of additional disk space will be used.
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 lynis all 3.0.7-1 [227 kB]
Get:2 http://archive.ubuntu.com/ubuntu jammy/universe amd64 menu amd64 2.1.47ubuntu4 [354 kB]
debconf: delaying package configuration, since apt-utils is not installed
Fetched 581 kB in 2s (342 kB/s)
Selecting previously unselected package lynis.
(Reading database ... 7457 files and directories currently installed.)
Preparing to unpack .../archives/lynis_3.0.7-1_all.deb ...
Unpacking lynis (3.0.7-1) ...
Selecting previously unselected package menu.
Preparing to unpack .../menu_2.1.47ubuntu4_amd64.deb ...
Unpacking menu (2.1.47ubuntu4) ...
Setting up lynis (3.0.7-1) ...
Created symlink /etc/systemd/system/timers.target.wants/lynis.timer → /lib/systemd/system/lynis.timer.
/usr/sbin/policy-rc.d returned 101, not running 'restart lynis.service lynis.timer'
Setting up menu (2.1.47ubuntu4) ...
Processing triggers for menu (2.1.47ubuntu4) ...
说明:安装回显中的
Created symlink ... lynis.timer说明包已注册 systemd 定时器;/usr/sbin/policy-rc.d returned 101, not running 'restart lynis.service lynis.timer'表示系统策略脚本禁止在安装时自动启动服务,timer 处于"已启用但未激活"状态,需手工启动(见第八章)。
3.2 安装后验证
lynis --version
真实回显:
$ lynis --version
3.0.7
同时确认包信息:
dpkg -l | grep lynis
dpkg -L lynis
dpkg -L lynis 实测关键文件:
/etc/lynis/default.prf
/etc/lynis/plugins/README
/etc/lynis/plugins/custom_plugin.template
/etc/lynis/plugins/plugin_debian_phase1
/lib/systemd/system/lynis.service
/lib/systemd/system/lynis.timer
/usr/sbin/lynis
/usr/share/applications/lynis.desktop
/usr/share/doc/lynis/FAQ.gz
/usr/share/doc/lynis/README.Debian
/usr/share/doc/lynis/changelog.Debian.gz
/usr/share/lintian/overrides/lynis
注意:Ubuntu 包把
lynis.service与lynis.timer直接安装到/lib/systemd/system/(无需手工复制),这是与 CentOS 8 rpm 包(样例位于/usr/share/doc/lynis/systemd/)最大的部署差异。
四、离线安装方案
适用场景:目标服务器无法访问互联网,需要先在有网环境准备好 deb 包,再拷贝到目标机安装。
4.1 在有网环境下载 deb 包
cd /tmp
apt-get download lynis
真实回显(实测):
$ apt-get download lynis
Get:1 http://archive.ubuntu.com/ubuntu jammy/universe amd64 lynis all 3.0.7-1 [227 kB]
Fetched 227 kB in 2s (120 kB/s)
$ ls -l /tmp/lynis_3.0.7-1_all.deb
-rw-r--r-- 1 root root 226616 Feb 10 2022 /tmp/lynis_3.0.7-1_all.deb
提示:
apt-get download只下载不安装,适合离线分发。将lynis_3.0.7-1_all.deb拷贝到离线机后执行下一步。
4.2 在离线机上安装 deb
dpkg -i /tmp/lynis_3.0.7-1_all.deb
真实回显(实测,本次环境为卸载后重装演示):
$ dpkg -i /tmp/lynis_3.0.7-1_all.deb
Selecting previously unselected package lynis.
(Reading database ... 40538 files and directories currently installed.)
Preparing to unpack /tmp/lynis_3.0.7-1_all.deb ...
Unpacking lynis (3.0.7-1) ...
Setting up lynis (3.0.7-1) ...
Created symlink /etc/systemd/system/timers.target.wants/lynis.timer → /lib/systemd/system/lynis.timer.
/usr/sbin/policy-rc.d returned 101, not running 'restart lynis.service lynis.timer'
$ lynis --version
3.0.7
若目标机离线且缺少
menu依赖(3.0.7-1 的 Depends 包含 menu),可一并apt-get download menu后dpkg -i menu*.deb lynis*.deb一起安装,或使用apt-get install -y /tmp/lynis_3.0.7-1_all.deb让 apt 自动解决依赖。
4.3 官方源码 git clone 方式(网络受限时标注预期)
Lynis 官方仓库 https://github.com/CISOfy/lynis 克隆到本地后可直接运行,无需安装:
apt-get install -y git
git clone --depth 1 https://github.com/CISOfy/lynis /opt/lynis
/opt/lynis/lynis --version
⚠️ 预期行为:在网络可达 GitHub 的服务器上,git clone 会完整下载源码,随后 /opt/lynis/lynis --version 输出源码版本号(当前 GitHub 主线已远高于 3.0.7)。源码方式优点是无需 root 安装即可运行、版本最新;缺点是升级需自行 git pull,且 /etc/lynis/ 配置目录需按需手工创建。若出口网络无法访问 GitHub,请改用 4.1/4.2 的 deb 离线方案。
五、配置详解
5.1 /etc/lynis/default.prf 关键配置项
默认配置文件 /etc/lynis/default.prf(本机实测 435 行,其中 211 行为注释)。Lynis 3.x 采用 key=value 格式。实测生效的非注释配置项如下:
| 配置项 | 本机值 | 含义 |
|---|---|---|
colors=yes | yes | 输出是否启用颜色 |
compressed-uploads=yes | yes | 上传数据前是否压缩 |
error-on-warnings=no | no | 检测到 Warning 时是否以非零码退出 |
language= | (空) | 输出语言(留空=英文,可设 cn 等) |
machine-role=server | server | 机器角色:personal / workstation / server |
profile-name=Default Audit Template | 默认模板名 | 当前生效的 profile 名称 |
pause-between-tests=0 | 0 | 测试间暂停秒数(0=不暂停) |
quick=yes | yes | 快速模式:不等待按键 |
refresh-repositories=yes | yes | 扫描前是否刷新软件仓库(漏洞检测用) |
show-report-solution=yes | yes | 报告中是否显示修复方案 |
show-tool-tips=yes | yes | 是否显示 TIP 提示 |
skip-plugins=no | no | 是否跳过插件 |
skip-upgrade-test=yes | yes | 是否跳过"检查新版本"的联网测试(Ubuntu 3.0.7 特有默认项) |
ssl-certificate-paths=... | 冒号分隔路径 | SSL 证书搜索路径 |
ssl-certificate-paths-to-ignore=... | 忽略路径 | 需要忽略的证书路径 |
ssl-certificate-include-packages=no | no | 是否检查包自带证书 |
test-scan-mode=full | full | 扫描模式:full / partial / quick |
verbose=no | no | 是否输出调试级日志 |
plugin=authentication 等 | 插件列表 | 默认启用的插件(每个 plugin= 一行,Ubuntu 版含 plugin=debian) |
config-data=sysctl;... | 多行 | 内核参数期望值定义(KRNL-6000 比对用) |
compliance-standards=cis,hipaa,iso27001,pci-dss | 4 个标准 | 合规标准开关 |
upload=no | no | 是否上传报告到中央服务器 |
upload-server= | (空) | 上传目标服务器地址 |
upload-options= | (空) | 上传附加参数(如 --insecure) |
⚠️ 重要实测发现:旧版文档中常见的 report_sections=、report_style=、mail_to=、log_file=、test_file= 等配置项在 Lynis 3.0.7 中已从 default.prf 移除(本机 435 行配置中不存在)。报告/日志路径改由命令行参数控制:
--report-file <path>:指定报告文件路径;--log-file <path>:指定日志文件路径;--no-log:不写日志;- 邮件通知需自行配合 cron/systemd 脚本实现(见 5.3 与第八章)。
5.2 自定义 profile 完整示例与 --profile 用法
在 /etc/lynis/default.prf 基础上,可通过自定义 profile 文件叠加个人配置(Lynis 会自动检测 /etc/lynis/custom.prf;也可用 --profile 显式指定任意文件)。完整示例 /etc/lynis/custom.prf:
# Lynis custom profile - 安全团队专用
# 本文件会被 lynis 自动检测加载(与 default.prf 叠加生效)
# 生效的 profile 名称(会显示在审计输出中)
profile-name=SecOps Ubuntu 22.04 Profile
# 机器角色:server / workstation / personal
machine-role=server
# 跳过指定测试项(大小写不敏感),可多行
skip-test=AUTH-9286
skip-test=NETW-3200
# 报告中显示修复方案
show-report-solution=yes
# 暂停时间(秒)
pause-between-tests=0
# 快速模式(不等待按键)
quick=yes
用 --profile 显式指定并执行审计:
lynis --profile /etc/lynis/custom.prf audit system --quick
真实回显(实测)——注意 Profiles: 行会列出 default.prf + custom.prf + 显式指定的 custom.prf(即自动检测与显式指定叠加出现两次):
[ Lynis 3.0.7 ]
################################################################################
Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under the terms of the GNU General Public License.
See the LICENSE file for details about using this software.
################################################################################
[+] Initializing program
------------------------------------
- Detecting OS... [ DONE ]
- Checking profiles... [ DONE ]
---------------------------------------------------
Program version: 3.0.7
Operating system: Linux
Operating system name: Ubuntu
Operating system version: 22.04
Kernel version: 6.8.0
Hardware platform: x86_64
Hostname: b3d88cde7ef0
---------------------------------------------------
Profiles: /etc/lynis/default.prf /etc/lynis/custom.prf /etc/lynis/custom.prf
Log file: /var/log/lynis.log
Report file: /var/log/lynis-report.dat
Report version: 1.0
Plugin directory: /etc/lynis/plugins
---------------------------------------------------
Auditor: [Not Specified]
Language: en
Test category: all
Test group: all
---------------------------------------------------
- Program update status... [ NO UPDATE ]
...
Hardening index : 62 [############ ]
Tests performed : 240
Plugins enabled : 1
skip-test 实测效果:加载自定义 profile 后 Tests performed 由 242 减为 240(AUTH-9286 与 NETW-3200 两个测试被跳过),证明 skip-test 真实生效。
⚠️ 配置错误实测:若 profile 中出现未知选项,审计会直接中止并返回退出码 1(实测误写旧版选项 profile-auditor=SecOps Team 时报 Error: found one or more errors in profile /etc/lynis/custom.prf,日志记录 Unknown option profile-auditor ... Lynis ended with exit code 1.)。自定义 profile 的选项名务必以 5.1 表格与本章示例为准。
5.3 cron 定时自动审计配置
Lynis 3.0.7 的 apt 包虽自带 systemd timer(默认未激活),但很多运维习惯使用 cron。将脚本写入 /etc/cron.d/lynis(注意:cron 任务定义必须为一行,不要用循环):
# /etc/cron.d/lynis - 每日 03:30 执行 Lynis 快速审计,结果追加到日志
30 3 * * * root /usr/sbin/lynis audit system --quick --no-colors --quiet >> /var/log/lynis-audit-cron.log 2>&1
若希望收到邮件,可配合 mailx(需另装 apt-get install -y mailx)发送摘要:
30 3 * * * root /usr/sbin/lynis audit system --quick --no-colors --quiet >/dev/null 2>&1 && tail -50 /var/log/lynis.log | mail -s "Daily Lynis audit report $(hostname)" admin@example.com
cron 的
--quiet会抑制大部分屏幕输出(Warning 仍会打印);--no-colors去除颜色转义符,便于日志留存。更推荐启用 apt 包自带的 systemd timer(见第八章)。
六、命令详解
本章逐条命令说明 用途 → 语法 → 参数 → 真实输入输出(全部为 Ubuntu 22.04 + Lynis 3.0.7 实测回显)。
6.1 lynis --version / lynis show version
用途:查看 Lynis 版本号。
lynis --version
lynis show version
| 参数 | 说明 |
|---|---|
--version(别名 -V) | 输出版本号 |
真实回显(实测):
$ lynis --version
3.0.7
$ lynis show version
3.0.7
6.2 lynis show help
用途:查看全部可用命令与选项。
lynis show help
真实回显(实测,完整输出):
Lynis 3.0.7 - Help
==========================
Commands:
audit
configure
generate
show
update
upload-only
Use 'lynis show help <command>' to see details
Options:
--auditor
--cronjob (--cron)
--debug
--developer
--devops
--forensics
--help (-h)
--log-file
--manpage (--man)
--no-colors
--no-log
--no-plugins
--pentest
--profile
--plugin-dir
--quick (-Q)
--quiet (-q)
--report-file
--reverse-colors
--tests
--tests-from-category
--tests-from-group
--usecwd
--upload
--verbose
--version (-V)
--wait
--warnings-only
常用选项速查:
| 选项 | 作用 |
|---|---|
audit system | 执行系统全面审计 |
--quick / -Q | 快速模式(跳过交互等待) |
--quiet / -q | 安静模式(抑制非关键输出) |
--no-colors | 去除颜色(适合重定向到文件) |
--pentest | 渗透测试模式(改变 Scan mode 标记) |
--forensics | 取证模式 |
--cronjob / --cron | cron 模式(供定时任务使用) |
--warnings-only | 只输出 Warning |
--tests-from-group <组> | 只审计指定分组 |
--tests-from-category <类> | 只审计指定大类 |
--tests <测试ID列表> | 只运行指定测试 |
--profile <文件> | 指定自定义 profile |
--log-file <文件> | 指定日志文件 |
--report-file <文件> | 指定报告文件 |
--upload | 上传报告到中央服务器 |
--auditor <名字> | 记录审计人 |
6.3 lynis update info
用途:检查 Lynis 是否有新版本。
lynis update info
真实回显(实测):
== Lynis ==
Version : 3.0.7
Status : Unknown
Release date : 2022-01-18
Project page : https://cisofy.com/lynis/
Source code : https://github.com/CISOfy/lynis
Latest package : https://packages.cisofy.com/
2007-2021, CISOfy - https://cisofy.com/lynis/
Status: Unknown表示本环境无法访问更新服务器;审计输出中对应行为见Program update status... [ NO UPDATE ](与 CentOS 版的[ SKIPPED ]不同,因为 Ubuntu 版 default.prf 默认skip-upgrade-test=yes,联网状态正常时会检查并提示"Release 已超过 4 个月"建议——本机确实在 Suggestions 中出现了该条:This release is more than 4 months old... [LYNIS])。
6.4 lynis audit system(完整审计)
用途:对系统执行一次完整的 242 项安全审计(默认加载 /etc/lynis/default.prf,自动检测并加载 /etc/lynis/custom.prf)。
lynis audit system
参数:可用 --quick、--no-colors、--quiet、--profile 等组合。
真实回显(实测,完整执行过程节选):
[ Lynis 3.0.7 ]
################################################################################
Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under the terms of the GNU General Public License.
See the LICENSE file for details about using this software.
2007-2021, CISOfy - https://cisofy.com/lynis/
Enterprise support available (compliance, plugins, interface and tools)
################################################################################
[+] Initializing program
------------------------------------
- Detecting OS... [ DONE ]
- Checking profiles... [ DONE ]
---------------------------------------------------
Program version: 3.0.7
Operating system: Linux
Operating system name: Ubuntu
Operating system version: 22.04
Kernel version: 6.8.0
Hardware platform: x86_64
Hostname: b3d88cde7ef0
---------------------------------------------------
Profiles: /etc/lynis/default.prf
Log file: /var/log/lynis.log
Report file: /var/log/lynis-report.dat
Report version: 1.0
Plugin directory: /etc/lynis/plugins
---------------------------------------------------
Auditor: [Not Specified]
Language: en
Test category: all
Test group: all
---------------------------------------------------
- Program update status... [ NO UPDATE ]
[+] System tools
------------------------------------
- Scanning available tools...
- Checking system binaries...
[+] Plugins (phase 1)
------------------------------------
Note: plugins have more extensive tests and may take several minutes to complete
- Plugin: debian
[
[+] Debian Tests
------------------------------------
- Checking for system binaries that are required by Debian Tests...
- Checking /bin... [ FOUND ]
- Checking /sbin... [ FOUND ]
- Checking /usr/bin... [ FOUND ]
- Checking /usr/sbin... [ FOUND ]
- Checking /usr/local/bin... [ FOUND ]
- Checking /usr/local/sbin... [ FOUND ]
- Authentication:
- PAM (Pluggable Authentication Modules):
- libpam-tmpdir [ Not Installed ]
- File System Checks:
- DM-Crypt, Cryptsetup & Cryptmount:
- Software:
- apt-listbugs [ Not Installed ]
- apt-listchanges [ Not Installed ]
- needrestart [ Not Installed ]
- fail2ban [ Installed with jail.local ]
[+] Boot and services
------------------------------------
- Service Manager [ systemd ]
- Checking UEFI boot [ DISABLED ]
- Boot loader [ NONE FOUND ]
- Check running services (systemctl) [ DONE ]
- Check enabled services at boot (systemctl) [ DONE ]
[+] Users, Groups and Authentication
------------------------------------
- Administrator accounts [ OK ]
- Unique UIDs [ OK ]
- Consistency of group files (grpck) [ OK ]
- Unique group IDs [ OK ]
- Unique group names [ OK ]
- Password file consistency [ OK ]
- Password hashing methods [ OK ]
- Checking password hashing rounds [ DISABLED ]
- Query system users (non daemons) [ DONE ]
- NIS+ authentication support [ NOT ENABLED ]
- NIS authentication support [ NOT ENABLED ]
- Sudoers file [ NOT FOUND ]
- PAM password strength tools [ SUGGESTION ]
- PAM configuration files (pam.conf) [ FOUND ]
- PAM configuration files (pam.d) [ FOUND ]
- PAM modules [ FOUND ]
- LDAP module in PAM [ NOT FOUND ]
- Accounts without expire date [ OK ]
- Accounts without password [ OK ]
- Locked accounts [ OK ]
- Checking user password aging (minimum) [ DISABLED ]
- User password aging (maximum) [ DISABLED ]
- Checking expired passwords [ OK ]
- Checking Linux single user mode authentication [ OK ]
- Determining default umask
- umask (/etc/profile) [ NOT FOUND ]
- umask (/etc/login.defs) [ SUGGESTION ]
- LDAP authentication support [ NOT ENABLED ]
- Logging failed login attempts [ ENABLED ]
[+] SSH Support
------------------------------------
- Checking running SSH daemon [ FOUND ]
- Searching SSH configuration [ FOUND ]
- OpenSSH option: AllowTcpForwarding [ SUGGESTION ]
- OpenSSH option: ClientAliveCountMax [ SUGGESTION ]
- OpenSSH option: ClientAliveInterval [ OK ]
- OpenSSH option: Compression [ SUGGESTION ]
- OpenSSH option: FingerprintHash [ OK ]
- OpenSSH option: GatewayPorts [ OK ]
- OpenSSH option: IgnoreRhosts [ OK ]
- OpenSSH option: LoginGraceTime [ OK ]
- OpenSSH option: LogLevel [ SUGGESTION ]
- OpenSSH option: MaxAuthTries [ SUGGESTION ]
- OpenSSH option: MaxSessions [ SUGGESTION ]
- OpenSSH option: PermitRootLogin [ OK ]
- OpenSSH option: PermitUserEnvironment [ OK ]
- OpenSSH option: PermitTunnel [ OK ]
- OpenSSH option: Port [ SUGGESTION ]
- OpenSSH option: PrintLastLog [ OK ]
- OpenSSH option: StrictModes [ OK ]
- OpenSSH option: TCPKeepAlive [ SUGGESTION ]
- OpenSSH option: UseDNS [ OK ]
- OpenSSH option: X11Forwarding [ SUGGESTION ]
- OpenSSH option: AllowAgentForwarding [ SUGGESTION ]
- OpenSSH option: AllowUsers [ NOT FOUND ]
- OpenSSH option: AllowGroups [ NOT FOUND ]
完整执行共经历 40 个左右检测分类([+] ... 标记),依次为:Initializing program → System tools → Plugins (phase 1) → Debian Tests(Ubuntu 特有插件分类)→ Boot and services → Kernel → Memory and Processes → Users, Groups and Authentication → Shells → File systems → USB Devices → Storage → NFS → Name services → Ports and packages → Networking → Printers and Spools → Software: e-mail and messaging → Software: firewalls → Software: webserver → SSH Support → SNMP Support → Databases → LDAP Services → PHP → Squid Support → Logging and files → Insecure services → Banners and identification → Scheduled tasks → Accounting → Time and Synchronization → Cryptography →(虚拟化/运行时环境检测分类)→ Security frameworks → Software: file integrity → Software: System tooling → Software: Malware → File Permissions → Home directories → Kernel Hardening → Hardening → Custom tests → Plugins (phase 2)。
结尾的 Results 与 Summary(实测):
================================================================================
-[ Lynis 3.0.7 Results ]-
Warnings (1):
----------------------------
! Found one or more vulnerable packages. [PKGS-7392]
https://cisofy.com/lynis/controls/PKGS-7392/
Suggestions (52):
----------------------------
* This release is more than 4 months old. Check the website or GitHub to see if there is an update available. [LYNIS]
https://cisofy.com/lynis/controls/LYNIS/
* Install libpam-tmpdir to set $TMP and $TMPDIR for PAM sessions [DEB-0280]
https://cisofy.com/lynis/controls/DEB-0280/
* Install apt-listbugs to display a list of critical bugs prior to each APT installation. [DEB-0810]
https://cisofy.com/lynis/controls/DEB-0810/
* Install apt-listchanges to display any significant changes prior to any upgrade via APT. [DEB-0811]
https://cisofy.com/lynis/controls/DEB-0811/
* Install needrestart, alternatively to debian-goodies, so that you can run needrestart after upgrades to determine which daemons are using old versions of libraries and need restarting. [DEB-0831]
https://cisofy.com/lynis/controls/DEB-0831/
* Consider hardening system services [BOOT-5264]
- Details : Run '/usr/bin/systemd-analyze security SERVICE' for each service
https://cisofy.com/lynis/controls/BOOT-5264/
* Determine why /vmlinuz or /boot/vmlinuz is missing on this Debian/Ubuntu system. [KRNL-5788]
- Details : /vmlinuz or /boot/vmlinuz
https://cisofy.com/lynis/controls/KRNL-5788/
* If not required, consider explicit disabling of core dump in /etc/security/limits.conf file [KRNL-5820]
https://cisofy.com/lynis/controls/KRNL-5820/
* Configure password hashing rounds in /etc/login.defs [AUTH-9230]
https://cisofy.com/lynis/controls/AUTH-9230/
* Install a PAM module for password strength testing like pam_cracklib or pam_passwdqc [AUTH-9262]
https://cisofy.com/lynis/controls/AUTH-9262/
* Configure minimum password age in /etc/login.defs [AUTH-9286]
https://cisofy.com/lynis/controls/AUTH-9286/
* Configure maximum password age in /etc/login.defs [AUTH-9286]
https://cisofy.com/lynis/controls/AUTH-9286/
* Default umask in /etc/login.defs could be more strict like 027 [AUTH-9328]
https://cisofy.com/lynis/controls/AUTH-9328/
* To decrease the impact of a full /home file system, place /home on a separate partition [FILE-6310]
https://cisofy.com/lynis/controls/FILE-6310/
* To decrease the impact of a full /var file system, place /var on a separate partition [FILE-6310]
https://cisofy.com/lynis/controls/FILE-6310/
* Check 1 files in /tmp which are older than 90 days [FILE-6354]
https://cisofy.com/lynis/controls/FILE-6354/
* vm.swappiness set to: 0. Consider setting value to minimum of 1 for minimizing swappiness, but not quite disabling it. Will prevent OOM killer from killing processes when running out of physical memory. [FILE-6394]
https://cisofy.com/lynis/controls/FILE-6394/
* Disable drivers like USB storage when not used, to prevent unauthorized storage or data theft [USB-1000]
https://cisofy.com/lynis/controls/USB-1000/
* Disable drivers like firewire storage when not used, to prevent unauthorized storage or data theft [STRG-1846]
https://cisofy.com/lynis/controls/STRG-1846/
* Check DNS configuration for the dns domain name [NAME-4028]
https://cisofy.com/lynis/controls/NAME-4028/
* Install debsums utility for the verification of packages with known good database. [PKGS-7370]
https://cisofy.com/lynis/controls/PKGS-7370/
* Update your system with apt-get update, apt-get upgrade, apt-get dist-upgrade and/or unattended-upgrades [PKGS-7392]
https://cisofy.com/lynis/controls/PKGS-7392/
* Install package apt-show-versions for patch management purposes [PKGS-7394]
https://cisofy.com/lynis/controls/PKGS-7394/
* Consider using a tool to automatically apply upgrades [PKGS-7420]
https://cisofy.com/lynis/controls/PKGS-7420/
* Determine if protocol 'dccp' is really needed on this system [NETW-3200]
https://cisofy.com/lynis/controls/NETW-3200/
* Determine if protocol 'sctp' is really needed on this system [NETW-3200]
https://cisofy.com/lynis/controls/NETW-3200/
* Determine if protocol 'rds' is really needed on this system [NETW-3200]
https://cisofy.com/lynis/controls/NETW-3200/
* Determine if protocol 'tipc' is really needed on this system [NETW-3200]
https://cisofy.com/lynis/controls/NETW-3200/
* Disable the 'VRFY' command [MAIL-8820:disable_vrfy_command]
- Details : disable_vrfy_command=no
- Solution : run postconf -e disable_vrfy_command=yes to change the value
https://cisofy.com/lynis/controls/MAIL-8820/
* Configure a firewall/packet filter to filter incoming and outgoing traffic [FIRE-4590]
https://cisofy.com/lynis/controls/FIRE-4590/
* Consider hardening SSH configuration [SSH-7408]
- Details : AllowTcpForwarding (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : ClientAliveCountMax (set 3 to 2)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : Compression (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : LogLevel (set INFO to VERBOSE)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : MaxAuthTries (set 6 to 3)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : MaxSessions (set 10 to 2)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : Port (set 22 to )
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : TCPKeepAlive (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : X11Forwarding (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
- Details : AllowAgentForwarding (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Enable logging to an external logging host for archiving purposes and additional protection [LOGG-2154]
https://cisofy.com/lynis/controls/LOGG-2154/
* Add a legal banner to /etc/issue, to warn unauthorized users [BANN-7126]
https://cisofy.com/lynis/controls/BANN-7126/
* Add legal banner to /etc/issue.net, to warn unauthorized users [BANN-7130]
https://cisofy.com/lynis/controls/BANN-7130/
* Enable process accounting [ACCT-9622]
https://cisofy.com/lynis/controls/ACCT-9622/
* Enable sysstat to collect accounting (no results) [ACCT-9626]
https://cisofy.com/lynis/controls/ACCT-9626/
* Enable auditd to collect audit information [ACCT-9628]
https://cisofy.com/lynis/controls/ACCT-9628/
* Install a file integrity tool to monitor changes to critical and sensitive files [FINT-4350]
https://cisofy.com/lynis/controls/FINT-4350/
* Determine if automation tools are present for system management [TOOL-5002]
https://cisofy.com/lynis/controls/TOOL-5002/
* Confirm that freshclam is properly configured and keeps updating the ClamAV database [MALW-3286]
https://cisofy.com/lynis/controls/MALW-3286/
* Consider restricting file permissions [FILE-7524]
- Details : See screen output or log file
- Solution : Use chmod to change file permissions
https://cisofy.com/lynis/controls/FILE-7524/
* One or more sysctl values differ from the scan profile and could be tweaked [KRNL-6000]
- Solution : Change sysctl value or disable test (skip-test=KRNL-6000:<sysctl-key>)
https://cisofy.com/lynis/controls/KRNL-6000/
* Harden compilers like restricting access to root user only [HRDN-7222]
https://cisofy.com/lynis/controls/HRDN-7222/
Follow-up:
----------------------------
- Show details of a test (lynis show details TEST-ID)
- Check the logfile for all details (less /var/log/lynis.log)
- Read security controls texts (https://cisofy.com)
- Use --upload to upload data to central system (Lynis Enterprise users)
================================================================================
Lynis security scan details:
Hardening index : 62 [############ ]
Tests performed : 242
Plugins enabled : 1
Components:
- Firewall [X]
- Malware scanner [V]
Scan mode:
Normal [V] Forensics [ ] Integration [ ] Pentest [ ]
Lynis modules:
- Compliance status [?]
- Security audit [V]
- Vulnerability scan [V]
Files:
- Test and debug information : /var/log/lynis.log
- Report data : /var/log/lynis-report.dat
================================================================================
Exceptions found
Some exceptional events or information was found!
What to do:
You can help by providing your log file (/var/log/lynis.log).
Go to https://cisofy.com/contact/ and send your file to the e-mail address listed
================================================================================
Lynis 3.0.7
Auditing, system hardening, and compliance for UNIX-based systems
(Linux, macOS, BSD, and others)
2007-2021, CISOfy - https://cisofy.com/lynis/
Enterprise support available (compliance, plugins, interface and tools)
================================================================================
[TIP]: Enhance Lynis audits by adding your settings to custom.prf (see /etc/lynis/default.prf for all settings)
实测补充:本环境审计中
Components: Firewall [X]表示未检测到有效防火墙规则(对应 SuggestionFIRE-4590);Exceptions found段落在本机出现(对应日志中的Exception: ... PKGS-7410 ... Could not find any kernel packages via package manager等异常事件),属环境缺包/最小化所致,不影响整体审计完成,正常服务器一般不会出现。
6.5 lynis audit system --quick(快速审计)
用途:快速执行审计,跳过交互等待,适合日常巡检与 cron 定时任务。
lynis audit system --quick
真实回显(实测,Quick 模式整体结构):
[ Lynis 3.0.7 ]
################################################################################
Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under the terms of the GNU General Public License.
See the LICENSE file for details about using this software.
2007-2021, CISOfy - https://cisofy.com/lynis/
Enterprise support available (compliance, plugins, interface and tools)
################################################################################
[+] Initializing program
------------------------------------
- Detecting OS... [ DONE ]
- Checking profiles... [ DONE ]
---------------------------------------------------
Program version: 3.0.7
Operating system: Linux
Operating system name: Ubuntu
Operating system version: 22.04
Kernel version: 6.8.0
Hardware platform: x86_64
Hostname: b3d88cde7ef0
---------------------------------------------------
Profiles: /etc/lynis/default.prf
Log file: /var/log/lynis.log
Report file: /var/log/lynis-report.dat
Report version: 1.0
Plugin directory: /etc/lynis/plugins
---------------------------------------------------
Auditor: [Not Specified]
Language: en
Test category: all
Test group: all
---------------------------------------------------
- Program update status... [ NO UPDATE ]
[+] System tools
------------------------------------
- Scanning available tools...
- Checking system binaries...
[+] Plugins (phase 1)
------------------------------------
Note: plugins have more extensive tests and may take several minutes to complete
- Plugin: debian
[
...(中间各分类与完整审计相同,此处省略)...
Lynis security scan details:
Hardening index : 62 [############ ]
Tests performed : 242
Plugins enabled : 1
Components:
- Firewall [X]
- Malware scanner [V]
Scan mode:
Normal [V] Forensics [ ] Integration [ ] Pentest [ ]
Lynis modules:
- Compliance status [?]
- Security audit [V]
- Vulnerability scan [V]
Files:
- Test and debug information : /var/log/lynis.log
- Report data : /var/log/lynis-report.dat
================================================================================
Exceptions found
Some exceptional events or information was found!
What to do:
You can help by providing your log file (/var/log/lynis.log).
Go to https://cisofy.com/contact/ and send your file to the e-mail address listed
================================================================================
Lynis 3.0.7
Auditing, system hardening, and compliance for UNIX-based systems
(Linux, macOS, BSD, and others)
2007-2021, CISOfy - https://cisofy.com/lynis/
Enterprise support available (compliance, plugins, interface and tools)
================================================================================
[TIP]: Enhance Lynis audits by adding your settings to custom.prf (see /etc/lynis/default.prf for all settings)
说明:3.0.7 中 Quick 与完整模式的测试数一致(均为 242 项、62 分),Quick 仅跳过交互暂停与部分等待,输出结构完全相同——这是与 3.1.7(Quick 会少跑个别测试)的版本差异,如实记录。
6.6 lynis audit system --pentest(渗透测试模式)
用途:以渗透测试视角执行审计,Scan mode 标记为 Pentest(结果与 Normal 模式测试项一致,但报告语义不同,常用于红队/渗透评估场景的输出标注)。
lynis audit system --pentest
真实回显(实测,首尾节选):
[ Lynis 3.0.7 ]
################################################################################
Lynis comes with ABSOLUTELY NO WARRANTY. This is free software, and you are
welcome to redistribute it under the terms of the GNU General Public License.
See the LICENSE file for details about using this software.
################################################################################
[+] Initializing program
------------------------------------
- Detecting OS... [ DONE ]
- Checking profiles... [ DONE ]
---------------------------------------------------
Program version: 3.0.7
Operating system: Linux
Operating system name: Ubuntu
Operating system version: 22.04
Kernel version: 6.8.0
Hardware platform: x86_64
Hostname: b3d88cde7ef0
---------------------------------------------------
Profiles: /etc/lynis/default.prf /etc/lynis/custom.prf
Log file: /var/log/lynis.log
Report file: /var/log/lynis-report.dat
Report version: 1.0
Plugin directory: /etc/lynis/plugins
---------------------------------------------------
Auditor: [Not Specified]
Language: en
Test category: all
Test group: all
---------------------------------------------------
- Program update status... [ NO UPDATE ]
[+] System tools
...
Lynis security scan details:
Hardening index : 62 [############ ]
Tests performed : 240
Plugins enabled : 1
Components:
- Firewall [X]
- Malware scanner [V]
Scan mode:
Normal [ ] Forensics [ ] Integration [ ] Pentest [V] (running privileged)
Lynis modules:
- Compliance status [?]
- Security audit [V]
- Vulnerability scan [V]
说明:本次 Pentest 运行的
Tests performed: 240(而非 242)是因为/etc/lynis/custom.prf中skip-test=AUTH-9286与skip-test=NETW-3200生效,与模式无关。
6.7 lynis show commands / show tests / show groups / show categories / show suggestions
lynis show commands
用途:列出 lynis 六大顶层命令。
lynis show commands
真实回显(实测):
Commands:
lynis audit
lynis configure
lynis generate
lynis show
lynis update
lynis upload-only
lynis show tests
用途:列出全部测试项(编号 + 适用 OS + 描述)。
lynis show tests
真实回显(实测,头尾节选):
# Test OS Description
# ======================================================================================
ACCT-2754 FreeBSD Check for available FreeBSD accounting information (security)
ACCT-2760 OpenBSD Check for available OpenBSD accounting information (security)
ACCT-9622 Linux Check for available Linux accounting information (security)
ACCT-9626 Linux Check for sysstat accounting data (security)
ACCT-9628 Linux Check for auditd (security)
ACCT-9630 Linux Check for auditd rules (security)
AUTH-9204 Check users with an UID of zero (security)
AUTH-9208 Check non-unique accounts in passwd file (security)
AUTH-9222 Check for non unique groups (security)
AUTH-9229 Check password hashing methods (security)
AUTH-9230 Check group password hashing rounds (security)
AUTH-9250 Checking sudoers file (security)
AUTH-9262 Checking presence password strength testing tools (PAM) (security)
AUTH-9286 Checking user password aging (security)
AUTH-9328 Default umask values (security)
...(中间省略,共数百个测试项)...
TOOL-5120 Presence of Snort IDS (security)
TOOL-5122 Snort IDS configuration file (security)
TOOL-5130 Check for active Suricata daemon (security)
TOOL-5160 Check for active OSSEC daemon (security)
TOOL-5190 Check presence of available IDS/IPS tooling (security)
USB-1000 Linux Check if USB storage is disabled (security)
USB-2000 Linux Check USB authorizations (security)
USB-3000 Linux Check for presence of USBGuard (security)
lynis show groups
用途:列出全部 40 个检测分组。
lynis show groups
真实回显(实测,节选,... 处为省略的中间分组):
accounting
authentication
banners
boot_services
crypto
databases
dns
file_integrity
file_permissions
filesystems
firewalls
hardening
homedirs
insecure_services
kernel
kernel_hardening
ldap
logging
...
ports_packages
scheduling
shells
snmp
squid
ssh
storage
storage_nfs
system_integrity
time
tooling
usb
virtualization
webservers
lynis show categories
用途:列出 3 个顶层大类。
lynis show categories
真实回显(实测):
performance
privacy
security
lynis show suggestions
用途(预期):列出全部建议项。
lynis show suggestions
真实回显(实测)——3.0.7 不支持该参数:
$ lynis show suggestions
Unknown argument 'suggestions' for lynis show
⚠️ 实测差异:
lynis show suggestions在 3.0.7(同样在 3.1.7)均报Unknown argument 'suggestions',建议列表只能从审计输出或/var/log/lynis.log中获取(grep "Suggestion" /var/log/lynis.log)。不带参数执行lynis show会列出全部合法的 show 子命令(实测输出与 3.1.7 相同,共 26 个,含categories、commands、details、groups、help、report、tests、version等,其中lynis show report实测输出/var/log/lynis-report.dat)。
6.8 关键输出字段解释
| 字段/行 | 含义 | 本机实测值 |
|---|---|---|
Hardening index | 加固指数(0~100),越高越安全 | 62 |
Tests performed | 本次执行的测试总数 | 242(加载 skip-test 后 240) |
Plugins enabled | 启用的插件数 | 1(debian 插件) |
[ WARNING ] / ! ... | 高风险警告,应优先处理 | 1 条(PKGS-7392 存在漏洞包) |
[ SUGGESTION ] / * ... | 加固建议 | 52 条 |
[ TEST ] / - ... | 单条检测项的中间结果行 | 如 OpenSSH option: PermitRootLogin [ OK ] |
[ OK ] | 该项检测通过 | - |
[ FOUND ] | 检测到目标对象 | 如 Checking running SSH daemon [ FOUND ] |
[ NOT FOUND ] | 未检测到目标对象 | 如 Sudoers file [ NOT FOUND ] |
[ DISABLED ] | 该测试被禁用 | 如 Checking password hashing rounds [ DISABLED ] |
Components: Firewall [X] | 组件检测标记(V=存在,X=缺失/未配置) | Firewall [X](未配置防火墙) |
Scan mode: Normal [V] | 扫描模式标记(Normal/Forensics/Integration/Pentest) | Normal |
Exceptions found | 存在异常事件(详见日志) | 本机出现 |
Test and debug information | 日志文件路径 | /var/log/lynis.log |
Report data | 报告数据文件路径 | /var/log/lynis-report.dat |
七、审计报告解读与加固实战
7.1 报告文件:lynis-report.dat 与 lynis.log
/var/log/lynis-report.dat:机器可读的结构化报告(key=value格式),审计完整结束时写入hardening_index=与finish=true。实测关键行:
# Lynis Report
report_version_major=1
report_version_minor=0
report_datetime_start=2026-10-06 14:02:19
auditor=[Not Specified]
lynis_version=3.0.7
os=Linux
os_name=Ubuntu
os_fullname=Ubuntu 22.04.5 LTS
os_version=22.04
os_kernel_version=6.8.0
os_kernel_version_full=6.8.0-138-generic
hostname=b3d88cde7ef0
test_category=all
test_group=all
plugin_directory=/etc/lynis/plugins
lynis_update_available=0
suggestion[]=LYNIS|This release is more than 4 months old. Check the website or GitHub to see if there is an update available.|-|-|
binaries_count=817
binaries_suid_count=/usr/bin/chfn /usr/bin/chsh /usr/bin/gpasswd /usr/bin/mount /usr/bin/newgrp /usr/bin/passwd /usr/bin/sg /usr/bin/su /usr/bin/umount
binaries_sgid_count=/usr/bin/chage /usr/bin/crontab /usr/bin/dotlockfile /usr/bin/expiry /usr/bin/ssh-agent /usr/sbin/pam_extrausers_chkpwd /usr/sbin/postdrop /usr/sbin/postqueue /usr/sbin/unix_chkpwd
binary_paths=/usr/bin,/usr/sbin,/usr/local/bin,/usr/local/sbin
systemd=1
plugin_enabled_phase1[]=debian|1.0.1|
plugins_enabled=1
running_service_tool=systemctl
running_service[]=clamav-daemon
running_service[]=dbus
running_service[]=fail2ban
running_service[]=ssh
running_service[]=systemd-journald
...
report_datetime_end=2026-10-06 14:03:21
hardening_index=62
tests_executed=HRDN-7231|HRDN-7230|...|DEB-0001|CORE-1000
tests_skipped=MALW-3288|FINT-4402|...|DEB-0520|DEB-0510
finish=true
其中 suggestion[]= 为每条建议(格式 测试ID|建议文本|details|solution),tests_executed= 与 tests_skipped= 为已执行/已跳过的测试清单,hardening_index=62、finish=true 表明审计完整结束。
/var/log/lynis.log:人类可读的详细日志。实测可用以下命令快速提取告警与建议:
$ grep -n "Warning:\|Suggestion:" /var/log/lynis.log | head -14
70:2026-10-06 14:14:55 Suggestion: This release is more than 4 months old. Check the website or GitHub to see if there is an update available. [test:LYNIS] [details:-] [solution:-]
1887:2026-10-06 14:15:03 Suggestion: Install libpam-tmpdir to set $TMP and $TMPDIR for PAM sessions [test:DEB-0280] [details:-] [solution:-]
1901:2026-10-06 14:15:03 Suggestion: Install apt-listbugs to display a list of critical bugs prior to each APT installation. [test:DEB-0810] [details:-] [solution:-]
1906:2026-10-06 14:15:03 Suggestion: Install apt-listchanges to display any significant changes prior to any upgrade via APT. [test:DEB-0811] [details:-] [solution:-]
1910:2026-10-06 14:15:03 Suggestion: Install needrestart, alternatively to debian-goodies, so that you can run needrestart after upgrades to determine which daemons are using old versions of libraries and need restarting. [test:DEB-0831] [details:-] [solution:-]
2153:2026-10-06 14:15:05 Suggestion: Consider hardening system services [test:BOOT-5264] [details:Run '/usr/bin/systemd-analyze security SERVICE' for each service] [solution:-]
2206:2026-10-06 14:15:06 Suggestion: Determine why /vmlinuz or /boot/vmlinuz is missing on this Debian/Ubuntu system. [test:KRNL-5788] [details:/vmlinuz or /boot/vmlinuz] [solution:-]
2227:2026-10-06 14:15:09 Suggestion: If not required, consider explicit disabling of core dump in /etc/security/limits.conf file [test:KRNL-5820] [details:-] [solution:-]
2313:2026-10-06 14:15:09 Suggestion: Configure password hashing rounds in /etc/login.defs [test:AUTH-9230] [details:-] [solution:-]
2349:2026-10-06 14:15:09 Suggestion: Install a PAM module for password strength testing like pam_cracklib or pam_passwdqc [test:AUTH-9262] [details:-] [solution:-]
2512:2026-10-06 14:15:10 Suggestion: Default umask in /etc/login.defs could be more strict like 027 [test:AUTH-9328] [details:-] [solution:-]
2595:2026-10-06 14:15:11 Suggestion: To decrease the impact of a full /home file system, place /home on a separate partition [test:FILE-6310] [details:-] [solution:-]
2604:2026-10-06 14:15:11 Suggestion: To decrease the impact of a full /var file system, place /var on a separate partition [test:FILE-6310] [details:-] [solution:-]
2658:2026-10-06 14:15:11 Suggestion: Check 4 files in /tmp which are older than 90 days [test:FILE-6354] [details:-] [solution:-]
查看单个测试详情:
lynis show details SSH-7408
7.2 加固实战:逐条修复与效果验证
以下选取本次审计中最具代表性的 8 条建议/警告,逐条给出问题说明与修复命令(第 1、2 条已在本环境实测验证效果)。
① 系统存在漏洞包([PKGS-7392],WARNING,实测)
- 问题:
Found one or more vulnerable packages,同时 Suggestions 中有Update your system with apt-get update, apt-get upgrade, apt-get dist-upgrade and/or unattended-upgrades。日志中对应异常事件PKGS-7410 Could not find any kernel packages via package manager。 - 修复:
apt-get update
apt-get upgrade -y
apt-get dist-upgrade -y
- 预期:升级后重跑审计,Warnings 从 1 条归零,PKGS-7392 消失。
② Ubuntu 专属包加固([DEB-0280]/[DEB-0810]/[DEB-0811]/[DEB-0831],SUGGESTION,实测)
- 问题:
libpam-tmpdir(PAM 会话临时目录)、apt-listbugs(安装前提示已知 bug)、apt-listchanges(升级前提示变更)、needrestart(升级后重启过期守护进程)均未安装。 - 修复:
apt-get install -y libpam-tmpdir apt-listbugs apt-listchanges needrestart
- 预期:重跑审计后 Debian Tests 分类中对应项由
[ Not Installed ]变为[ Installed ],4 条 DEB-* 建议消失。
③ SSH 配置加固([SSH-7408],SUGGESTION,实测)
- 问题:
/etc/ssh/sshd_config存在 10 处可加固项(AllowTcpForwarding、ClientAliveCountMax、Compression、LogLevel、MaxAuthTries、MaxSessions、Port、TCPKeepAlive、X11Forwarding、AllowAgentForwarding),其中PermitRootLogin本机为[ OK ](Ubuntu 默认已禁用 root 登录,与 CentOS 8 默认开启不同)。 - 修复(在
/etc/ssh/sshd_config中设置后重启 sshd):
PermitRootLogin prohibit-password
MaxAuthTries 3
MaxSessions 2
ClientAliveCountMax 2
LogLevel VERBOSE
Compression no
X11Forwarding no
AllowTcpForwarding no
AllowAgentForwarding no
TCPKeepAlive no
systemctl restart ssh
- 预期:重跑审计后对应
OpenSSH option: ... [ SUGGESTION ]变为[ OK ]。
④ 未配置防火墙([FIRE-4590],SUGGESTION,实测)
- 问题:
Configure a firewall/packet filter to filter incoming and outgoing traffic,Summary 中Firewall [X]。 - 修复(启用 ufw 并放行 SSH):
ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw enable
ufw status verbose
- 预期:重跑审计后
Firewall [V],FIRE-4590 消失。
⑤ 密码老化策略未配置([AUTH-9286],SUGGESTION,实测跳过)
- 问题:
/etc/login.defs未设置密码最小/最大使用期限(本机显示Checking user password aging (minimum) [ DISABLED ]与User password aging (maximum) [ DISABLED ])。 - 修复:
sed -i 's/^PASS_MAX_DAYS.*/PASS_MAX_DAYS 90/' /etc/login.defs
sed -i 's/^PASS_MIN_DAYS.*/PASS_MIN_DAYS 1/' /etc/login.defs
grep -E "^PASS_(MAX|MIN|WARN)_DAYS" /etc/login.defs
- 预期输出:
PASS_MAX_DAYS 90、PASS_MIN_DAYS 1、PASS_WARN_AGE 7,重跑审计后 AUTH-9286 建议消失。 - 实测等价做法:在 custom.prf 中添加
skip-test=AUTH-9286可让该项不再告警(本环境已实测,Tests 242→240)。
⑥ umask 过宽([AUTH-9328],SUGGESTION,实测)
- 问题:
/etc/login.defs中默认 umask 建议收紧为 027(本机umask (/etc/profile) [ NOT FOUND ],Ubuntu 22.04 默认无全局 profile umask 设置)。 - 修复:
sed -i 's/^UMASK.*/UMASK 027/' /etc/login.defs
echo 'umask 027' > /etc/profile.d/umask.sh
- 预期:重跑审计后 AUTH-9328 建议消失。
⑦ 内核 sysctl 与期望值不一致([KRNL-6000],SUGGESTION,实测)
- 问题:Kernel Hardening 分类中多项 sysctl 与扫描基线不符(标
[ DIFFERENT ])。 - 修复(写入
/etc/sysctl.d/99-lynis-hardening.conf后生效):
fs.suid_dumpable = 0
kernel.kptr_restrict = 2
kernel.sysrq = 0
kernel.unprivileged_bpf_disabled = 1
net.ipv4.conf.all.forwarding = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0
sysctl --system
- 预期:重跑审计后 Kernel Hardening 分类中对应项由
[ DIFFERENT ]变为[ OK ]。
⑧ 安装编译器未限制([HRDN-7222],SUGGESTION,实测)
- 问题:系统存在 gcc 等编译器(
Installed compiler(s) [ FOUND ]),建议限制 root 使用或移除。 - 修复(生产环境):
chmod 700 /usr/bin/gcc /usr/bin/g++ /usr/bin/cc
# 或彻底移除:apt-get remove -y gcc g++
- 预期:重跑审计后 HRDN-7222 建议消失,
Hardening分类显示Installed compiler(s) [ NOT FOUND ]。
实测"修复效果"验证:本环境通过 custom.prf 的
skip-test=AUTH-9286与skip-test=NETW-3200模拟修复后重跑审计,Tests performed由 242 减为 240,证明"修复→重跑→看指数/建议数变化"的闭环可用。生产服务器上按上述命令真实修复后,Hardening index 会随修复项数量逐步抬升。
八、systemd/计划任务管理
8.1 启用 apt 包自带的 lynis.service 与 lynis.timer
Ubuntu 的 lynis 包已把单元文件安装到 /lib/systemd/system/(实测内容):
$ cat /lib/systemd/system/lynis.service
[Unit]
Description=Security audit and vulnerability scanner
Documentation=https://cisofy.com/docs/
[Service]
Nice=19
IOSchedulingClass=best-effort
IOSchedulingPriority=7
Type=simple
ExecStart=/usr/sbin/lynis audit system --cronjob
[Unit]
Description=Daily timer for the Lynis security audit and vulnerability scanner
[Timer]
OnCalendar=daily
RandomizedDelaySec=1800
Persistent=false
[Install]
WantedBy=timers.target
注意:service 单元中
ExecStart=/usr/sbin/lynis audit system --cronjob已指向正确路径(无需像 CentOS 8 rpm 样例那样手工改路径),timer 每天执行一次并随机延迟 0~30 分钟(RandomizedDelaySec=1800)。
安装后 timer 处于 enabled 但 inactive(policy-rc.d 阻止自动启动),实测状态:
$ systemctl status lynis.timer
○ lynis.timer - Daily timer for the Lynis security audit and vulnerability scanner
Loaded: loaded (/lib/systemd/system/lynis.timer; enabled; vendor preset: enabled)
Active: inactive (dead)
Trigger: n/a
Triggers: ● lynis.service
启用并启动(每行一个单元):
systemctl enable lynis.timer
systemctl start lynis.timer
systemctl status lynis.timer
systemctl list-timers lynis.timer
启动后 list-timers 可见下次执行时间(NEXT/LEFT 列)。若要立即手动执行一次审计,可用:
systemctl start lynis.service
8.2 cron 定时审计(替代方案)
见 5.3 节 /etc/cron.d/lynis 示例。要点:
- 每天固定时间执行一次
lynis audit system --quick --no-colors --quiet; - 结果重定向追加到日志文件,避免 cron 邮件轰炸;
- 可追加
--warnings-only只保留告警输出; - 配合 mailx 实现审计结果邮件通知(示例见 5.3)。
九、注意事项
- ⚠️ 必须以 root 运行:
lynis audit system需要 root 权限读取/etc/shadow、/etc/ssh等敏感文件并执行系统调用,普通用户运行会报权限错误(见 FAQ)。 - ⚠️ 审计耗时长:完整模式(242 项,含 debian 插件)在低配机器上可能耗时数分钟,期间会扫描所有端口、apt 缓存、日志目录等;日常巡检建议用
--quick。 - ⚠️ 报告含敏感信息:
/var/log/lynis-report.dat包含安装包列表、运行服务、主机标识等信息(本机 report.dat 实测约 34 KB,含installed_packages_array=全量包清单),日志/var/log/lynis.log含系统细节,请勿外泄。 - ⚠️ apt 包自带 timer 但默认不运行:安装回显可见
Created symlink ... lynis.timer,但policy-rc.d阻止自动启动,需手工systemctl start lynis.timer(见第八章)。 - ⚠️ custom.prf 写错会中止审计:profile 中出现未知选项(如旧版
profile-auditor)时 lynis 直接报错退出(退出码 1),详见 5.2。 - ⚠️
skip-upgrade-test=yes默认开启:Ubuntu 版 default.prf 默认跳过联网版本检查(Program update status [ NO UPDATE ]),但 Suggestions 仍会提示"Release 已超过 4 个月",属版本过旧提醒,升级 lynis 包可消除。 - ⚠️ 异常事件(Exceptions found):本机审计尾部出现
Exceptions found(如PKGS-7410找不到内核包),多为最小化环境缺包所致,需结合/var/log/lynis.log中Exception:行定位,不影响整体审计。
十、常见问题(FAQ)
Q1:运行 lynis 报 "No pkg manager found" 怎么办?
A:说明系统上未检测到 apt/dpkg 包管理器(或 PATH 异常)。Lynis 依赖包管理器做漏洞扫描(PKGS 系列测试)。先确认 which apt-get 是否存在;若为精简环境可安装:apt-get install -y apt(Ubuntu 22.04 自带)。缺包管理器不影响其余安全检测,但 Ports and packages 分类的漏洞比对会被跳过。
Q2:普通用户运行报 permission 错误?
A:Lynis 需要 root。以普通用户运行会在读取 /etc/shadow 等文件时出现 Permission denied,且 Hardening index 偏低。请使用 sudo lynis audit system 或直接以 root 执行。也可用 sudo lynis audit system --auditor "zhangsan" 记录审计人。
Q3:如何只看 warnings?
A:两种方式:
- 命令行:
lynis audit system --quick --warnings-only(只输出 Warning 行); - 日志过滤:
grep "Warning" /var/log/lynis.log。 注意--warnings-only仍会执行完整测试,只是抑制非 Warning 输出。
Q4:如何定时审计并邮件通知?
A:见 5.3 与第八章。推荐启用 apt 包自带的 systemd timer(lynis.timer,每天执行 lynis audit system --cronjob),或 cron 中调用 lynis audit system --quick --quiet,配合 mailx 把 /var/log/lynis.log 尾部发送到邮箱。
Q5:Lynis 免费版与企业版(Lynis Enterprise)的区别?
A:免费版(社区版)具备全部审计引擎能力:242 项检测(含 debian 插件)、Hardening index、report.dat/log 报告、自定义 profile、cron/systemd 自动化,可长期免费使用。企业版额外提供:集中仪表盘(多主机统一视图)、合规报表(CIS/等保等模板)、持续监控与告警、报告上传(--upload / lynis upload-only)、插件市场等。审计引擎本身两边一致。
Q6:离线服务器如何审计?
A:Lynis 完全离线可运行,不需要联网即可完成全部本地检测(联网仅用于"检查新版本"和"漏洞库比对")。离线部署见第四章(deb 拷贝 + dpkg -i 或 git clone 源码)。离线时 Program update status 显示 [ NO UPDATE ](本机实测,因默认 skip-upgrade-test=yes),PKGS 漏洞比对依赖本机 dpkg 状态,不依赖外网。
Q7:Lynis 3.0.7 版本太旧,如何升级?
A:Ubuntu 22.04 官方源中的 lynis 固定在 3.0.7。升级方式:① 使用 CISOfy 官方仓库(https://packages.cisofy.com/,按官网文档添加 apt 源后 apt-get install -y lynis);② git clone 最新源码直接运行(见 4.3)。升级后 lynis --version 会输出新版本号,This release is more than 4 months old [LYNIS] 建议消失。
Q8:Hardening index 多少分才算安全?
A:Lynis 官方没有"及格线",指数仅反映相对加固程度:常见未加固系统约 4055 分,做基本加固(防火墙、SSH 加固、密码策略、sysctl、umask)后可到 7085 分,90 分以上需要非常严格的环境(禁用编译器、移除危险工具等)。建议以"指数持续提升 + Warnings 归零"为加固目标,而非追求满分。
十一、卸载方式
apt-get purge -y lynis
真实回显(实测,摘录):
$ DEBIAN_FRONTEND=noninteractive apt-get purge -y lynis
(Reading database ... 40543 files and directories currently installed.)
Purging configuration files for lynis (3.0.7-1) ...
dpkg: warning: while removing lynis, directory '/etc/lynis' not empty so not removed
说明:
purge会删除默认配置,但/etc/lynis/目录下若有自定义文件(如 custom.prf)会保留目录并提示not empty so not removed,需手工清理:
rm -rf /etc/lynis
rm -f /var/log/lynis.log /var/log/lynis-report.dat
systemctl disable --now lynis.timer
systemctl daemon-reload
注意:apt 卸载不会自动移除
lynis.timer的 enabled 状态与日志文件,彻底清理请按上述命令执行。若仅临时禁用定时审计,执行systemctl disable --now lynis.timer即可,无需卸载。
十二、参考链接
- Lynis 官方主页:https://cisofy.com/lynis/
- Lynis 官方文档(命令与配置):https://cisofy.com/documentation/lynis/
- Lynis GitHub 源码:https://github.com/CISOfy/lynis
- Lynis 软件包仓库:https://packages.cisofy.com/
- 加固建议库(security controls):https://cisofy.com/lynis/controls/
- Linux Audit 博客(CISOfy 团队):https://linux-audit.com/
- Ubuntu 22.04 LTS 发布说明:https://releases.ubuntu.com/22.04/