Join our Newsletter — 33% off our NHI Course
Home› Guides› Lynis Guide: Auditing and Hardening Linux and Unix…
Guide Endpoint Security

Lynis Guide: Auditing and Hardening Linux and Unix Hosts

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, under the editorial direction of Lalit Choda Updated 27 November 2026 14 min read
On this page

Most Linux estates have a hardening standard on paper and no quick, repeatable way to see how far each host has drifted from it. Lynis is an open source, host-based auditing tool from CISOfy that runs on the system itself, executes several hundred individual tests and returns warnings, suggestions and a hardening index. This guide explains what Lynis checks, how to run it safely, how to read its screen output and its report file field by field, what the hardening index does and does not tell you, and how to automate scans across a fleet. It is written for Linux administrators and security engineers who already own a baseline; for the baseline itself see the Linux Server Hardening Guide.

This is an independent guide from NHI Mgmt Group, based on CISOfy's public Lynis documentation and the project source code as of November 2026. It is not sponsored or reviewed by CISOfy. Product features change, so confirm settings against CISOfy's current documentation.

Key takeaways

  • Lynis is an auditor, not a fixer. It reads configuration and system state and tells you what to change; remediation stays with your configuration management, so a scan alone changes nothing on the host.
  • Run it as root for a full picture. A privileged lynis audit system covers every applicable test; --pentest runs a non-privileged scan and skips the tests that need root.
  • The report file is the real output. /var/log/lynis-report.dat holds machine-readable key=value lines, including every warning[] and suggestion[] with its test ID, which is what you feed into tickets, dashboards and a SIEM.
  • Treat the hardening index as a trend line. It is the ratio of hardening points earned to points available on that host, not a percentage of how safe the system is, and it only compares fairly between hosts that run the same tests.
  • Change behaviour through custom.prf. Leave default.prf untouched, record skipped tests and exceptions in a version-controlled custom.prf, and give every skip a reason and an owner.

What Lynis does

The project README describes Lynis as a security auditing tool for UNIX-based systems that "performs an in-depth security scan and runs on the system itself", with goals of automated security auditing, compliance testing and vulnerability detection. CISOfy lists support for AIX, FreeBSD, HP-UX, Linux, macOS, NetBSD, NixOS, OpenBSD and Solaris, and states that its tests draw on CIS Benchmarks, NIST, NSA, OpenSCAP data and vendor guides. It is written in shell, needs no compilation or agent, and is released under the GPLv3. The scan is modular: Lynis detects which components are present (SSH, a web server, a database, a firewall) and runs only the tests that apply.

Each test has a stable identifier made of a group prefix and a number, such as SSH-7408 or AUTH-9228. Tests are also tagged with a category (security, performance or privacy). The table summarises the main test groups in the open source release, counted from the project's include/tests_* files.

Group prefixAreaExample test and what it checks
AUTHAuthentication, accounts, PAM, sudoAUTH-9228: password file consistency with pwck
SSHOpenSSH server configurationSSH-7408: specific sshd options such as root login and log level
BOOTBoot loader, services, UEFIBOOT-5122: GRUB boot password set
KRNLKernel version, modules, sysctlKRNL-6000: sysctl key pairs compared with values in the scan profile
PKGSPackage managers, updates, vulnerable packagesPKGS-7392: pending Debian or Ubuntu security updates
FILE, HOMEFile systems, mount options, permissionsFILE-6310: separate /tmp, /home and /var
ACCT, LOGGAccounting, auditd, syslog and log rotationACCT-9628: auditd present; LOGG-2154: syslog configuration
FIRE, NETWHost firewall and network settingsFIRE-4512: empty iptables ruleset
MACFMandatory access controlMACF-6208: AppArmor enabled
FINT, MALW, HRDNFile integrity, malware scanners, compiler exposureFINT-4350: file integrity tool installed; HRDN-7222: compiler permissions
CRYP, TIMECertificates, encrypted swap, time syncCRYP-7902: certificate expiry; TIME-3104: NTP daemon or client running
INSE, HTTP, DBS, MAIL, NAMELegacy services, web servers, databases, mail, DNSINSE tests: insecure services such as inetd entries
CONT, USB, SCHD, SHLLContainers, USB storage, cron and at, shellsUSB-1000: USB storage disabled

Lynis complements rather than replaces a formal benchmark scanner. Use it for fast, broad coverage and trend tracking; use the CIS-CAT or OpenSCAP content for your distribution when an auditor needs control-by-control evidence against a named benchmark. See the CIS Benchmarks Guide.

NeedLynisBenchmark scanner (CIS-CAT, OpenSCAP)
Quick health check of an unknown hostStrong fit: no install, broad coverageSlower to set up, profile per distribution
Evidence against a named benchmarkIndicative onlyStrong fit: rule-level pass or fail per profile
Mixed Unix estate (BSD, AIX, macOS)One tool across platformsContent varies by platform
Trend of hardening over timeHardening index and finding countsCompliance percentage per profile
Automated remediationNone (advice only)Some content ships remediation scripts

Running audits

Install from your distribution, from the CISOfy package repository, or by cloning the GitHub repository; the README notes that some distributions ship older versions and recommends the CISOfy repository or the latest release in that case. Lynis 3.1.7 was released on 25 June 2026, and from 3.1.6 the tool treats a release six months or older as old. Older copies miss newer test logic and end-of-life data, so keep the version current.

  1. Prepare: if you run from a cloned or extracted copy as root, change ownership to root first (the README suggests chown -R 0:0), otherwise Lynis warns that it is executing files owned by an unprivileged user. Lynis also needs write access to /tmp.
  2. Run a full audit: sudo lynis audit system. Add --quick (-Q) to stop the pauses between sections and --auditor "Name" to stamp the report.
  3. Run without root where you must: lynis audit system --pentest performs a non-privileged scan. The manual page states that tests requiring root are skipped, and the output lists which were skipped, so do not compare these results with privileged scans.
  4. Scope a run: --tests "SSH-7408 AUTH-9228" runs named tests, --tests-from-group "ssh authentication" runs groups, and --tests-from-category security limits to a category. lynis show groups and lynis show categories list the valid values.
  5. Audit a container build file: lynis audit dockerfile Dockerfile checks a Dockerfile rather than a running host.
  6. Investigate a finding: lynis show details SSH-7408 prints what that test logged, and lynis show tests SSH-7408 describes the test.

Lynis refuses to run if its binary has the set-user-id bit, and it refuses to write a log or report file that is a symbolic link, to avoid symlink attacks. Running it is low risk on production hosts because it reads state; the main operational cost is a short burst of CPU and disk activity from package and file checks, so schedule fleet scans outside peak hours.

Reading results

Screen output shows each test with a status such as [ OK ], [ FOUND ], [ NOT FOUND ], [ WARNING ] or [ SUGGESTION ], followed by a summary. CISOfy's documentation makes two points worth repeating to every team: warnings "are events which really need an action", while suggestions "could indicate room for improvement" and are usually far more numerous; and an [ OK ] result does not always mean the system is correctly or securely configured. Every warning and suggestion carries a test ID and usually a link to further reading.

Two files hold the detail. When run as root the defaults are /var/log/lynis.log (a verbose log of every test and its reasoning, purged at the start of each scan) and /var/log/lynis-report.dat (the structured report). A non-privileged run writes both to the user's home directory. Copy or rotate them if you want history. The report uses one key=value per line; keys ending in [] repeat. The table lists fields you will use most, taken from the source code.

Report fieldContentTypical use
warning[]TEST-ID|message|details|solution|Raise a ticket or alert per warning
suggestion[]Same format as warningsHardening backlog, grouped by test ID
hardening_indexInteger from 0 to 100Trend per host and per role
lynis_version, report_datetime_start, report_datetime_end, auditorRun metadataEvidence and freshness checks
hostname, hostid, hostid2, os_name, os_version, os_kernel_versionHost identityJoin to the asset inventory
tests_executed, tests_skipped, lynis_tests_doneCoverage of this runDetect profiles that skip too much
vulnerable_packages_found, vulnerable_package[], available_update[]Package findings where a package audit tool existsFeed vulnerability management
firewall_active, firewall_installed, framework_selinux, file_integrity_tool[], malware_scanner[]Presence of key controlsControl coverage dashboards
real_user[], account_without_password[], locked_account[], network_listen_port[]Accounts and exposed portsAccess reviews and attack surface

Read the log alongside the report before you act: searching the log for a test ID shows exactly which file or command produced the result. Triage in this order: warnings, then suggestions in the authentication, SSH, logging and package groups, then the rest. The account and port fields are where an audit turns into an identity task, because service accounts, accounts without passwords and SSH keys need owners. See the Linux PAM Guide and the Linux Logging and auditd for Defenders Guide for the most common follow-up work.

Hardening index

The hardening index is calculated in the source as hardening points earned divided by the maximum points available, multiplied by 100. Individual tests award points through a function that adds a score and a maximum for that item, so a test that finds a control fully in place earns all its points and a partial result earns some. Tests that do not apply to a host add nothing to either side. That design has three consequences.

  • Not a safety percentage: the author of Lynis writes that the number "is just an indicator on taken measures" and should not be confused with a percentage of how safe a system is. A host with an exposed, unpatched application can still score well.
  • Comparable only like for like: skipping tests in a profile changes both the points and the maximum, so compare hosts only when they share the same profile, role and Lynis version. Record the version with every score.
  • Raise it by fixing, not by skipping: the honest way to move the number is to implement the control the test looks for. Skips that exist only to lift the score hide risk.

Use the index for direction (is this role improving release by release?) and for outliers (which web servers sit well below their peers?). Set targets per role rather than one fleet number, because a minimal container host and a general purpose bastion have different test sets.

Profiles and tailoring

Profiles control behaviour. default.prf carries the initial values and its own header says not to edit it; copy only your changes into custom.prf in the same directory, or point to another file with --profile. lynis show profiles shows which profiles were found, and lynis show settings shows the resulting configuration. Lynis checks profile lines strictly to avoid harmful injections.

SettingDefault in default.prfWhen to change it
skip-test=SSH-7408 or skip-test=SSH-7408:permitrootloginCommented outA documented exception for a whole test or one option within it
machine-roleserverSet workstation or personal for desktops so advice fits the role
error-on-warningsnoSet yes in pipelines so any warning returns exit code 78
quickyesLeave on for unattended runs
uploadnoOnly used with a central Lynis Enterprise or compatible collector
plugin= linesPlugins listed, some for Lynis Enterprise only--no-plugins for minimal runs

Keep custom.prf in version control with one comment per skip naming the reason, the approver and a review date. Build one profile per role (bastion, web, database, container host) so the hardening index stays comparable within each role.

Automation

Lynis becomes useful at scale when scans run on a schedule and the report lands somewhere people look. A phased rollout keeps noise manageable.

  1. Pilot: run privileged scans by hand on five to ten representative hosts per role, triage every warning, and write the first custom.prf per role.
  2. Schedule: use lynis audit system --cronjob, which turns off colours and pauses for unattended use, from cron or a systemd timer, weekly or after each patch cycle. Copy the report to a timestamped file so the next run does not overwrite history.
  3. Collect centrally: ship lynis-report.dat to your log pipeline or SIEM, parse warning[], suggestion[] and hardening_index, and join on hostid or hostname to the asset inventory. Restrict access to these files, because they map accounts, open ports and missing controls.
  4. Gate builds: in image pipelines set error-on-warnings=yes so a golden image that produces any warning fails with exit code 78 before it is published.
  5. Close the loop: fix findings in your configuration management (Ansible, Puppet, Salt or similar), never by hand on one host, and re-scan to confirm. See the Configuration Drift and Baseline Enforcement Guide.
  6. Roll back safely: if a remediation breaks a service, revert the configuration management change, re-run Lynis to record the state, and log a time-boxed exception in custom.prf rather than silently skipping the test.

Small teams can run Lynis by hand monthly and keep reports in a shared folder. Larger estates need the central pipeline, per-role targets and an owner per finding group; CISOfy's commercial Lynis Enterprise adds central dashboards, but the open source report is enough to build your own.

Detection and measurement

  • Coverage: percentage of in-scope Linux and Unix hosts with a privileged Lynis report less than 8 days old.
  • Warnings open: count of warning[] entries per role, with age; aim for zero warnings older than one patch cycle.
  • Hardening index trend: median and lowest score per role, per Lynis version, month on month.
  • Exception hygiene: number of skip-test lines and the share with an owner and review date.
  • Drift: findings that reappear after being fixed, which point to a gap in configuration management.

Also alert on a sudden fall in a host's index or a rise in tests_skipped, which can mean a profile change, a broken package audit tool or tampering with the host.

Common failure patterns

  • Scoring the unprivileged scan: --pentest results are compared with root scans and look better or worse for reasons unrelated to hardening.
  • Skipping to the target: teams add skip-test lines until the index meets a KPI. Tie targets to warnings closed, not just the score.
  • Running an old copy: a stale distribution package misses newer tests and end-of-life data, so results look cleaner than they are.
  • Losing history: the log is purged and the report overwritten on every run, so without copies there is no audit trail.
  • Fixing by hand: admins correct a finding directly on one host, configuration management reverts it, and the finding returns next week.
  • Leaving reports world readable: a report collected to a shared location gives an intruder a map of weak accounts and open ports.

Framework mapping

FrameworkReferenceHow Lynis supports it
NIST SP 800-53 Rev. 5CM-6 Configuration Settings; CM-7 Least FunctionalityChecks settings and flags unneeded services and compilers
NIST SP 800-53 Rev. 5RA-5 Vulnerability Monitoring and Scanning; CA-7 Continuous MonitoringScheduled host scans with vulnerable package and trend data
NIST CSF 2.0PR.PS-01; ID.RA-01; DE.CM-09Configuration practice evidence, vulnerability identification, runtime monitoring
CIS Controls v8.1Control 4 Secure Configuration of Enterprise Assets and SoftwareVerifies the secure configuration process on each host
ISO/IEC 27001:2022 Annex AA.8.8 Management of technical vulnerabilities; A.8.9 Configuration managementRecurring evidence that baselines are applied and reviewed

Practitioner checklist

  • Install a current Lynis release from the CISOfy repository or GitHub and track the version in every report.
  • Run privileged lynis audit system scans; keep --pentest results separate.
  • Create one version-controlled custom.prf per server role and never edit default.prf.
  • Give every skip-test a reason, an approver and a review date.
  • Schedule --cronjob runs and keep timestamped copies of the log and report.
  • Ship lynis-report.dat to central logging with restricted access and parse warnings, suggestions and the hardening index.
  • Fail image builds on warnings with error-on-warnings=yes.
  • Remediate through configuration management and re-scan to confirm.
  • Assign owners to accounts and listening services surfaced in the report.
  • Report coverage, open warnings and index trend per role each month.

Standards and references

Related NHI Mgmt Group resources: Linux Server Hardening Guide · CIS Benchmarks Guide · Configuration Drift and Baseline Enforcement Guide · Linux Logging and auditd for Defenders Guide · CIS Controls Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick both boxes to continue.