Geavanceerd
Zoeken inHow-to-gidsen
Zo zoek je
  • Typ de taak in je eigen woorden (poort vinden, firewall openen, schijf vol) of plak een foutmelding tussen aanhalingstekens.
  • Kies "Snel antwoord" om alleen de commando's te zien, of een gebied om in één vakgebied te blijven.
  • "twee woorden" vindt precies die zin.
  • Gewone woorden vinden namen, teksten en voorbeelden.
  • ↑ ↓ bewegen · Enter openen · Esc sluiten · / zoeken
Probeer:

How-to 119Security · Audit

How to audit a server with Lynis

"How secure is this server?" needs a number and a to-do list, not a feeling. Lynis checks hundreds of settings — SSH, users, file permissions, kernel, firewall, logging, installed tools — and gives a hardening index plus concrete suggestions. This how-to runs it, reads the report, fixes the most important findings, and tracks the score over time.

  • 5 Lessen
  • 5 Commando's

Dit deel is nog niet vertaald. Je ziet de Engelse tekst.

$ als gewone gebruiker# als root (of met sudo)

119.1

The quick answer

dnf -y install epel-release && dnf -y install lynis
apt-get install -y lynis
lynis audit system --quick
grep -E '^(hardening_index|warning|suggestion)' /var/log/lynis-report.dat | head -20

Use the dnf line on RHEL, the apt-get line on Ubuntu.

119.2

Step by step

  1. Run the audit as root (quick answer). --quick = no pauses between sections. It takes 1–3 minutes and changes nothing.
  2. Read the end of the output first:
  Lynis security scan details:
  Hardening index : 64 [############        ]
  Tests performed : 262

The index is a guide (higher = better), not a grade for an audit. The warnings and suggestions are what matter.

  1. List the findings with their test IDs:
grep '^warning' /var/log/lynis-report.dat
warning[]=SSH-7408|SSH option PermitRootLogin should be set to no|-|-|
grep '^suggestion' /var/log/lynis-report.dat | head
suggestion[]=AUTH-9230|Configure password hashing rounds in /etc/login.defs|-|-|
lynis show details SSH-7408
  1. Fix in order: warnings first, then suggestions that close real risks (SSH, users, firewall, updates, logging). Typical quick wins: harden SSH, install updates, enable auditd/AIDE, set password rules, remove compilers and unused services on production servers.
  2. Skip what does not fit — in a custom profile, with a reason:
/etc/lynis/custom.prf
# USB storage is needed on this backup server (ticket SEC-210)
skip-test=USB-1000
  1. Track over time: run it monthly (timer/cron), keep the hardening_index per server in your monitoring or a spreadsheet, and compare after changes. For formal compliance (CIS, STIG, PCI) use OpenSCAP with a profile — Lynis is the fast general check.

119.3

Check that it worked

After your fixes, run the audit again: the warnings you fixed are gone, and the hardening index is higher.

lynis audit system --quick > /dev/null && grep hardening_index /var/log/lynis-report.dat
hardening_index=78

119.4

Common problems

ProblemCauseFix
lynis: command not found on RHELNot in the base repos.Enable EPEL, or run it from the Git download.
Old checks / version warningThe distro package is old.Use the current version from the Lynis repo or Git.
Findings that do not applyGeneral checks vs your server's role.skip-test in a custom profile with a reason.
A "fix" broke the appHardening without testing (for example removing a needed package).Test on staging; change one thing at a time.
Different scores on similar serversDifferent packages or settings (drift).Use Ansible roles so servers are the same.
Auditor asks for a specific standardLynis is not a CIS report.OpenSCAP with the CIS/STIG profile for formal reports.

119.5

Go further

1Where does Lynis write the machine-readable results?

In /var/log/lynis-report.dat (warnings, suggestions, hardening index).

2How do you tell Lynis to skip a test that does not fit your server?

Add skip-test=TEST-ID with a reason in a custom profile (/etc/lynis/custom.prf).

Alle commando's in dit hoofdstuk