What it does
Lynis (CISOfy, open source) runs local tests on boot, kernel, users, SSH, file systems, firewall, logging, packages, crypto, containers and more. It prints warnings and suggestions (each with a test ID like SSH-7408) and a hardening index (0–100). It needs no agent and changes nothing, so it is a quick first check on a new server and a good way to measure progress after hardening.
For formal compliance (CIS, STIG, PCI-DSS) on RHEL use OpenSCAP; Lynis is the fast general check.
How to write it
lynis audit system [OPTIONS]
lynis show details TEST-IDMain parts
Commands
auditsystem- Full local audit.
showdetailsTEST-ID- Explain one test.
showprofiles/showsettings- Profile and settings.
updateinfo- Version check.
Options 7
Most used
Flags
Nothing matches this filter.
Examples 10
$ run as a normal user# run as root (or with sudo)
1Install and run
2See the hardening index and warnings
grep -E "hardening_index|warning\[\]" /var/log/lynis-report.dat3List all suggestions
4Explain one test
lynis show details SSH-74085Check only SSH and the firewall
lynis audit system --quick --tests-from-group "ssh firewalls"6Skip tests that do not apply
cat /etc/lynis/custom.prf skip-test=USB-1000 skip-test=STRG-1846 lynis audit system --quick --profile /etc/lynis/custom.prf7Run every week and keep the reports
cat /etc/cron.weekly/lynis #!/bin/sh lynis audit system --cronjob > /var/log/lynis-$(date +%F).log 2>&18Compare the index before and after hardening
9Run as a normal user
lynis audit system --pentest --quick10Read the full log of one test
grep -A5 "Performing test ID AUTH-9230" /var/log/lynis.log
Nothing matches this filter.
Watch out
- A high index is not "secure"; read the warnings, and decide each suggestion for your case.
- Reports contain details about your system — keep them private.
Files
/var/log/lynis.log- Detailed log.
/var/log/lynis-report.dat- Machine-readable report.
/etc/lynis/default.prf, custom.prf- Profiles.
Tips to remember
- Run Lynis on the golden image in the Packer pipeline and fail the build when the index drops.
Exit codes
0 | Success. |
1 | Error. |
78 | Warnings found (with --error-on-warnings). |