Lynis

On this page 7

Lynis is an open-source security auditing tool for Linux and other Unix-like systems that inspects a running host, compares its configuration with established hardening practice and produces a prioritized list of warnings and suggestions. In Linux security, it serves as a host-based assessment scanner: it does not block attacks or change settings by itself, but it shows administrators where a system deviates from a secure baseline.

The tool is written as a portable shell script, licensed under the GPLv3, and maintained by CISOfy. Because it needs no agent, no database and no compilation, it runs on servers, desktops, container hosts and embedded devices alike, which makes it a common first step in system hardening and in preparing for compliance reviews.

How Lynis audits a Linux host

Lynis works by executing hundreds of individual tests, each identified by a stable test ID such as AUTH-9328 or SSH-7408. A typical run starts with lynis audit system, which detects the operating system, kernel version, package manager and installed services, and then skips tests that do not apply to the detected platform.

Each test reads files, queries commands such as sysctl or ss, and evaluates the result against an expected value. The outcome is classified as OK, a suggestion or a warning, and every finding is written to two files: a human-readable log in /var/log/lynis.log and a machine-readable report in /var/log/lynis-report.dat. At the end, Lynis calculates a hardening index from 0 to 100, which summarizes how many weighted checks passed.

The following table lists the main components that shape every audit run.

ComponentLocation or commandPurpose
Test libraryinclude/ directoryGroups of shell functions per category
Profile/etc/lynis/default.prfDefines settings, skipped tests and thresholds
Custom profile/etc/lynis/custom.prfLocal overrides that survive upgrades
Log file/var/log/lynis.logDetailed trace of every test and result
Report file/var/log/lynis-report.datKey-value data for parsing and automation
Pluginsplugins/ directoryOptional extra data collection
Core components of a Lynis audit

Test categories and the hardening index

Lynis organizes its checks into categories that mirror the layers of a Linux system, from boot loader and kernel to user accounts, networking and logging. The prefix of each test ID shows its category, which makes it easy to filter results or to explain a single finding with lynis show details TEST-ID.

PrefixAreaTypical checks
BOOTBoot loader and servicesGRUB password, boot permissions
KRNLKernelsysctl values, core dump limits, loaded modules
AUTHAuthenticationPAM modules, password aging, sudo configuration
SSHOpenSSH daemonRoot login, password authentication, ciphers
FILEFile systemsMount options such as nodev, noexec and nosuid
MACFMandatory access controlAppArmor or SELinux status
LOGGLoggingRemote logging, rotation, journal settings
PKGSSoftware packagesVulnerable or outdated packages, automatic updates
Selected test categories and what they examine

The hardening index is a relative indicator, not a security score in an absolute sense. A freshly installed general-purpose distribution often scores in the 55-65 range, while a carefully hardened server commonly reaches 80 or higher. The value depends on which tests apply, so comparing indexes across different distributions or roles is of limited meaning; tracking the trend on the same host is far more useful.

Lynis is an auditing and assessment tool, which places it next to, but not in place of, the enforcement and detection tools of the same Topic. It reports that AppArmor is disabled or that Fail2ban is missing; it does not perform their functions.

ToolPrimary roleRelationship to Lynis
LynisConfiguration and hardening auditReference point of this comparison
OpenSCAPFormal compliance scanning with SCAP contentStricter, benchmark-driven, XCCDF reports
rkhunter and chkrootkitRootkit and backdoor detectionLook for compromise, not for weak settings
AIDEFile integrity monitoringDetects changes over time; Lynis checks if it exists
auditdKernel event auditingRecords system calls; Lynis verifies its configuration
ClamAVMalware scanningScans file content rather than configuration
How Lynis differs from neighboring tools

The practical consequence is that Lynis complements rather than replaces other controls. Many teams pair it with OpenSCAP for formal benchmarks such as CIS or DISA STIG profiles and with AIDE for integrity monitoring, using Lynis as the fast, broad first pass.

Running and configuring Lynis in practice

Lynis is available from distribution repositories, from the vendor package repository and as a tarball that runs without installation. Repository packages are convenient but can lag behind, so administrators who need current test coverage often use the vendor repository or the upstream release.

The command-line options control scope and output. The table below shows the options used most often and when each one fits.

Command or optionEffectWhen to use it
lynis audit systemFull local auditStandard run with root privileges
–pentestRuns as a non-privileged userSimulating what an attacker could see
–quickDisables pauses between sectionsInteractive runs without waiting
–cronjobQuiet, non-interactive, no colorsScheduled audits and automation
–profile fileLoads a specific profileRole-based baselines per server type
audit dockerfileAnalyzes a DockerfileReviewing container build definitions
Common invocation options

In a custom profile, administrators can skip tests that are not relevant with lines such as skip-test=SSH-7408, adjust thresholds and define the expected values. Skipping should always be documented with a reason, because silently suppressed tests hide real gaps and inflate the hardening index.

For fleets, the report file is the integration point: configuration management tools or simple scripts collect lynis-report.dat, extract keys such as warning[] and hardening_index, and feed them into dashboards. The commercial Lynis Enterprise edition adds central reporting and compliance mapping, but the open-source core performs the same tests.

Limitations and common mistakes

Lynis is valuable precisely because it is broad and simple, yet the same design brings clear limits that experienced practitioners respect.

  • It is not a vulnerability scanner: it checks configuration and package state, not exploitable flaws in running code.
  • A point-in-time snapshot: results describe the moment of the scan, so regular scheduled runs are required.
  • Chasing the score is a trap: raising the index by disabling irrelevant tests or applying every suggestion can break services.
  • Suggestions need context: a recommendation for a separate /tmp partition or a GRUB password may not suit a cloud instance.
  • Running from an untrusted copy defeats the purpose; verify packages or tarballs before execution as root.
  • A clean report is not proof of safety: a compromised host can hide evidence from tools that run on it.

A plain-language summary

Lynis is like a home inspector for a Linux computer. It walks through the system room by room, checks the locks, the alarms and the wiring, and then writes a list of what looks fine and what should be fixed.

It does not repair anything by itself. The administrator reads the list, decides which advice fits the machine, and makes the changes. The final number, the hardening index, is a rough progress meter, useful for seeing improvement over time rather than a guarantee that the computer is safe.

An example from practice

A small hosting team takes over twelve Ubuntu web servers with unknown history. Before changing anything, an administrator runs lynis audit system --cronjob on each machine and collects the report files. The average hardening index is 61, and the most frequent warnings point to SSH root login being permitted, no remote logging, and missing automatic security updates.

The team creates a shared custom profile, documents two skipped tests that do not apply to virtual machines, disables root login over SSH, enables unattended-upgrades, installs AIDE and forwards logs to a central server. A weekly scheduled run then tracks progress. After a month, the index rises to about 82 on every server, and new warnings now appear in the dashboard within a week instead of going unnoticed.