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.
| Component | Location or command | Purpose |
|---|---|---|
| Test library | include/ directory | Groups of shell functions per category |
| Profile | /etc/lynis/default.prf | Defines settings, skipped tests and thresholds |
| Custom profile | /etc/lynis/custom.prf | Local overrides that survive upgrades |
| Log file | /var/log/lynis.log | Detailed trace of every test and result |
| Report file | /var/log/lynis-report.dat | Key-value data for parsing and automation |
| Plugins | plugins/ directory | Optional extra data collection |
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.
| Prefix | Area | Typical checks |
|---|---|---|
| BOOT | Boot loader and services | GRUB password, boot permissions |
| KRNL | Kernel | sysctl values, core dump limits, loaded modules |
| AUTH | Authentication | PAM modules, password aging, sudo configuration |
| SSH | OpenSSH daemon | Root login, password authentication, ciphers |
| FILE | File systems | Mount options such as nodev, noexec and nosuid |
| MACF | Mandatory access control | AppArmor or SELinux status |
| LOGG | Logging | Remote logging, rotation, journal settings |
| PKGS | Software packages | Vulnerable or outdated packages, automatic updates |
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 compared with related Linux security tools
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.
| Tool | Primary role | Relationship to Lynis |
|---|---|---|
| Lynis | Configuration and hardening audit | Reference point of this comparison |
| OpenSCAP | Formal compliance scanning with SCAP content | Stricter, benchmark-driven, XCCDF reports |
| rkhunter and chkrootkit | Rootkit and backdoor detection | Look for compromise, not for weak settings |
| AIDE | File integrity monitoring | Detects changes over time; Lynis checks if it exists |
| auditd | Kernel event auditing | Records system calls; Lynis verifies its configuration |
| ClamAV | Malware scanning | Scans file content rather than configuration |
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 option | Effect | When to use it |
|---|---|---|
| lynis audit system | Full local audit | Standard run with root privileges |
| –pentest | Runs as a non-privileged user | Simulating what an attacker could see |
| –quick | Disables pauses between sections | Interactive runs without waiting |
| –cronjob | Quiet, non-interactive, no colors | Scheduled audits and automation |
| –profile file | Loads a specific profile | Role-based baselines per server type |
| audit dockerfile | Analyzes a Dockerfile | Reviewing container build definitions |
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.