Skip to content

Lynis: how to run it, read it, and triage the output

A practical guide to Lynis on a production Linux server — installing a current release, running lynis audit system, reading the hardening index correctly, and sorting the suggestions into fix now, fix in a window, and do not touch.

Lynis is a host-based security auditing script. You copy it onto a Linux server, run it locally as root, and it walks a few hundred tests across boot, kernel, authentication, filesystems, networking, SSH, web servers, databases and logging. There is no agent, no daemon and no central server: it runs, it writes two files, it exits. It is read-only by default — it reports, it does not remediate. The hard part is not running it. The hard part is deciding which of its suggestions to act on, because on a production web server a naive “fix everything Lynis says” pass is a reliable way to break customer sites.

What you’ll accomplish

  • Install a current Lynis release rather than whatever your distribution shipped years ago.
  • Run lynis audit system interactively once, then non-interactively on a schedule.
  • Read a finding properly: the test ID, the suggestion text, and where each lives in the two output files.
  • Understand why the hardening index is a relative indicator and not a number to maximise.
  • Sort the suggestion list into three buckets — apply now, apply in a change window, accept and record — with a defensible reason for each.
  • Record accepted risks in a profile file so the decision survives you, and diff runs so you see drift instead of re-reading the same 200 lines every week.

Prerequisites

  • Root or sudo on the host. Lynis will run unprivileged, but a large share of tests simply skip without root, and the resulting index is meaningless.
  • A supported Linux: AlmaLinux, Rocky, RHEL, Debian, Ubuntu and SUSE are all well covered. Lynis is written in shell script, so it also runs on macOS and the BSDs, with a smaller test set.
  • git or the ability to fetch a tarball, if you install from source (recommended — see step 1).
  • On a cPanel/WHM or web-stack box: know, before you start, which settings the control panel owns. cPanel manages PHP handlers, /tmp mount behaviour, MySQL configuration and a set of service defaults. Changing those out from under it is where outages come from.
  • A change window and a way to test customer sites afterwards, for anything in the second bucket.

How it works

Diagram of the Lynis audit pipeline: the script runs locally on the host, walks test groups such as boot, kernel, authentication and ssh, and writes a human log and a machine-readable report used for triage and drift checks

Lynis is a single shell program plus a directory of include files, one per test group. When you run lynis audit system, it detects the OS, works through each group in turn, and records three kinds of result: warnings (something is wrong now), suggestions (something could be tightened), and manual checks (it cannot determine the answer and is telling you to look).

Every result carries a test ID in a fixed format — a group prefix, a dash, and a number, like SSH-7408, AUTH-9262, FILE-6310, HRDN-7222, BANN-7126 or FINT-4350. The ID is the stable handle. It is what you search for when you want to know why a test fired, and it is what you write down when you decide to skip one.

Two files come out of a run. /var/log/lynis.log is the human transcript: every test, in order, with what it looked at. /var/log/lynis-report.dat is the machine-readable form — one field per line, in key=value shape, including hardening_index=, repeated warning[]= and suggestion[]= entries, and metadata about the run. That second file is what you parse for automation.

About the hardening index. Lynis prints a number out of 100 at the end, and it is the single most misread thing about the tool. It is a rough, relative indicator derived from how many tests passed against how many ran — it is not a grade, not a compliance score, and not comparable between two hosts running different services. A mail server and a WordPress front end will never converge on the same number, and they should not. Use it exactly one way: compare a host against its own previous run. A drop from 72 to 61 on the same box means something changed. Chasing 90 on a shared hosting server means you are about to disable something a customer pays you to keep running.

Step-by-step

  1. Install a current release, not the distribution package. The tests are the product, and packaged versions are frequently well behind upstream. Pull the source and link the script:

    sudo git clone https://github.com/CISOfy/lynis.git /usr/local/lynis
    sudo ln -s /usr/local/lynis/lynis /usr/local/bin/lynis
    lynis show version

    You should get a version string back. Compare it against the project’s release page; lynis update info will also tell you whether the copy you are running is current. To refresh later, git -C /usr/local/lynis pull and re-check the version. CISOfy also publishes signed distribution repositories if you would rather manage it through your package manager.

  2. Run the first audit interactively and watch it. The first time on a given host, do not automate it — read the output as it goes:

    sudo lynis audit system

    Lynis pauses between sections and waits for you to press Enter. That pause is useful on the first run and useless afterwards. Success looks like a section-by-section walk ending in a summary block with the hardening index, a warnings count and a suggestions count.

  3. Add the flags that make it useful. Once you know what a clean run looks like, the flags that matter are small in number:

    sudo lynis audit system --quick --auditor "ops-team" --no-colors \
      --report-file /var/log/lynis-report-$(date +%F).dat

    --quick (short form -Q) skips the between-section prompts, which is what you want for anything scripted. --auditor stamps a name into the report so a stored file says who ran it. --no-colors strips the escape codes that otherwise make a redirected log unreadable. --report-file and --log-file move the two outputs somewhere you choose. --cronjob is the scheduled-run mode — non-interactive and quiet, intended exactly for this. If you only care about one area, --tests-from-group ssh,authentication runs just those groups; lynis show groups lists the group names your version supports.

  4. Read the log first, then the report file. On the first pass, read /var/log/lynis.log end to end. It is long, but it is the only place that tells you what a test actually inspected. After that, the report file is faster:

    sudo grep '^hardening_index=' /var/log/lynis-report.dat
    sudo grep -c '^suggestion\[\]=' /var/log/lynis-report.dat
    sudo grep '^warning\[\]=' /var/log/lynis-report.dat

    Warning and suggestion lines are pipe-separated and begin with the test ID, so cutting the first field gives you a clean list of IDs to work through. Anything that can read a key=value file can consume this: a monitoring check, a config-management fact, a small script that posts the count to a dashboard.

  5. Look up a finding before you act on it. For any ID you do not recognise, search /var/log/lynis.log for it — the log shows what that test inspected on this host — and check the ID against the project documentation for what it wants. Never apply a suggestion you cannot explain to the person who owns the application on that host.

  6. Triage into three buckets. This is the step that matters, and it is the one most guides skip. Walk each suggestion through the same questions:

    Decision tree for triaging a single Lynis suggestion: whether it changes customer-visible behaviour, whether the control panel depends on it, whether it is reversible, and whether a change window exists

    Bucket A — apply now, low risk. Additive changes that nothing depends on. Installing and initialising a file integrity tool such as AIDE (FINT-4350). Enabling auditd and process accounting. Setting a login banner in /etc/issue and /etc/issue.net (BANN-7126). Turning on automatic security updates. Tightening an sshd_config option you have already confirmed nothing uses — but confirm it, because a forgotten deploy key or an rsync job over a forwarded port is exactly the thing that breaks silently.

    Bucket B — apply in a change window. Real changes with real blast radius, all of them recoverable if you are watching. Kernel sysctl hardening (KRNL-6000 and friends), where a value that looks harmless can change connection handling under load. Adding noexec and nosuid to /tmp and /dev/shm. Removing compilers (HRDN-7222). Separating filesystems onto their own partitions (FILE-6310). Disabling USB storage or unused kernel modules (STRG-1846). Each of these can be tested immediately after the window and rolled back in a minute — but only if you are on the console and the sites are open in a browser.

    Bucket C — do not blindly apply on a hosting box. Suggestions that are correct for a single-purpose server and wrong for a shared one. Disabling PHP functions a customer’s application calls, or changing open_basedir — the PHP runtime hardening article covers why that list has to be per-site, not global. Changing the system umask, which cPanel’s own tooling and mail delivery depend on. Mount options on /tmp on a cPanel box, where the panel manages that mount itself and expects to control it. Disabling services the panel needs — exim, cpsrvd, named — because Lynis has no idea they are load-bearing. For each of these the answer is not “ignore it”: it is to record the exception with a reason.

  7. Record what you accept, in a file, not in your memory. Lynis reads a custom.prf alongside its shipped default.prf — under /etc/lynis/ for a packaged install, or in the source directory otherwise. Never edit default.prf; an update will overwrite it. Add a skip-test= line per accepted finding, with a comment saying why:

    # /etc/lynis/custom.prf
    # HRDN-7222: gcc is required by the customer's node-gyp build. Reviewed 2026-09-08.
    skip-test=HRDN-7222
    # FILE-6310: single-volume VM, partitioning deferred to the next rebuild.
    skip-test=FILE-6310

    Then run against it with sudo lynis audit system --profile /etc/lynis/custom.prf --quick. Those suggestions stop appearing, and the file becomes your decision log — which is what an accepted risk is supposed to be.

  8. Schedule it and diff the results. Re-reading 200 suggestions weekly trains people to skim. Comparing runs does not:

    #!/bin/sh
    # /etc/cron.weekly/lynis-audit
    OUT=/var/log/lynis/report-$(date +%F).dat
    mkdir -p /var/log/lynis
    /usr/local/bin/lynis audit system --cronjob --profile /etc/lynis/custom.prf --report-file "$OUT"
    PREV=$(ls -1 /var/log/lynis/report-*.dat | tail -n 2 | head -n 1)
    [ -n "$PREV" ] && diff "$PREV" "$OUT"

    Make it executable with chmod +x. The output you care about is the diff: a new warning[]= line, or a hardening index that moved, means the host changed. That is a signal. The unchanged 200 are not.

Validate it works

Confirm the version you are running, that a scheduled run produces a parseable report, and that your skips are actually taking effect:

lynis show version
sudo lynis audit system --quick --profile /etc/lynis/custom.prf --report-file /tmp/lynis-check.dat
grep '^hardening_index=' /tmp/lynis-check.dat
grep -c '^suggestion\[\]=' /tmp/lynis-check.dat
grep -c 'HRDN-7222' /tmp/lynis-check.dat

The version should match upstream, hardening_index= should return a number, the suggestion count should be lower than your first run, and any test ID you skipped should return 0. If a skipped ID still appears, the profile is not being read — check the path you passed.

Troubleshooting

  • The hardening index dropped and nothing obvious changed. Almost always a package upgrade that reset a default, or a new service that brought new tests into scope. Diff the report files rather than guessing: the new warning[]= or suggestion[]= lines name the test.
  • Skipped tests keep reappearing. Either the profile is not being loaded (pass --profile explicitly and confirm the path), or you edited default.prf and an update replaced it. Keep every local decision in custom.prf.
  • The run takes far longer than expected. Network-facing and package-database tests dominate the time on a slow or heavily loaded host. --quick removes the interactive pauses; --tests-from-group narrows the scan when you only need one area.
  • A site broke right after a hardening pass. Work backwards from your own change list, not from the Lynis output. The usual culprits are mount options on /tmp, a sysctl value that changed connection handling, and a globally disabled PHP function. This is why bucket B belongs in a window with the sites open in front of you.
  • Suggestions look wrong for the machine. Lynis infers the machine role from what it finds. Explicitly setting the role in the profile file, and skipping groups that do not apply, gets you a report about the server you actually have.

When this is the wrong approach

Lynis is not a benchmark audit. It overlaps with CIS content in places, but it does not implement a CIS Benchmark, it does not map findings to control IDs, and passing it certifies nothing. If you need a formal, evidence-producing benchmark run, that is a different tool and a different process — see applying a CIS Benchmark. Lynis is also host-local by design: it tells you nothing about your network edge, your application code, or your dependencies, and it is not a vulnerability scanner. And it is a point-in-time audit — a passing score on a host nobody patches decays quietly.

The upstream project documentation at cisofy.com/lynis and the source at github.com/CISOfy/lynis are the authoritative references for test IDs, profile directives and release notes.

If this is the kind of work you’d rather never own again, it’s the daily job of Managed Cloud Ops — book an infrastructure review.