Knowledgebase

Find frequently asked questions and setup guides by searching or by browsing the categories.

What Lynis Does

Lynis is a shell script that runs on the server itself. It looks at the boot process, kernel settings, users and authentication, SSH, file permissions, installed software, firewall rules, logging, and the services that are running. It needs no agent and keeps no state between runs apart from its log and report files.

Install Lynis

On Debian it is in main, and on Ubuntu in universe:

sudo apt install lynis

On AlmaLinux and Rocky Linux it comes from EPEL:

sudo dnf install epel-release
sudo dnf install lynis

Distribution packages can lag behind the current release, and Lynis tells you during the run when it is outdated. The project also publishes its own package repository, and you can run the latest version straight from its source without installing it. Lynis checks that its own files belong to the user who runs it, so clone it as root when you will run it with sudo:

cd /usr/local
sudo git clone https://github.com/CISOfy/lynis
cd lynis
sudo ./lynis audit system

Check the installed version with lynis show version.

Run an Audit

sudo lynis audit system

Run it as root so it can read every configuration file. The scan takes a few minutes and prints its results section by section, then a summary with warnings, suggestions, and the hardening index. If your version pauses between sections, --quick runs it without waiting for input.

Read Warnings and Suggestions

  • Warnings: findings that deserve attention soon, such as a missing firewall or an outdated package with security fixes.
  • Suggestions: hardening ideas. Many are worth doing; some do not fit your server.
  • Test IDs: every finding has an ID in capital letters and digits. After a run, ask Lynis for what that test found, taken from its log, before you change anything.
sudo lynis show details SSH-7408

Make one change at a time, and treat anything that touches SSH or the firewall with the usual safe order: keep the current session open, test the configuration with its own check such as sshd -t, and log in from a second terminal before you close the first. Common SSH fixes are covered in how to disable SSH password authentication.

The Hardening Index

The hardening index is a number from 0 to 100 based on the tests that passed. Use it to compare runs of the same server over time, not as a target. Changing settings only to raise the number can break services without making the server safer. A suggestion you have reviewed and rejected can be skipped in a custom profile, custom.prf in the same directory as default.prf (/etc/lynis for a package), with a line such as skip-test=SSH-7408.

Log and Report Files

  • Log file: /var/log/lynis.log records every step of the run.
  • Report file: /var/log/lynis-report.dat holds the results as key=value lines.

To list only the findings:

sudo grep -E '^(warning|suggestion)' /var/log/lynis-report.dat

Both files are overwritten on the next run, so copy them with a date if you want a history.

Run It on a Schedule

--cronjob runs without colors, questions, or pauses, which suits a scheduled job. Find the installed path with command -v lynis, then add a weekly entry with sudo crontab -e:

0 4 * * 1 /usr/sbin/lynis audit system --cronjob > /dev/null 2>&1

Adjust the path to the one on your server. Scheduling is explained in how to create a cron job. Compare the report after each run and look into new warnings.

What Lynis Is Not

Lynis audits configuration. It is not a malware scanner and not a vulnerability scanner for your web applications: for that, see how to scan a Linux server for malware. It also does not replace the basics in initial server setup or regular updates, covered in how to enable automatic security updates. To record who changes important files between audits, add auditd.

Was this answer helpful?
Loading...