Lynis – Linux Security Auditing & System Hardening Guide

Lynis is a powerful, open-source security auditing and system hardening tool for Unix and Linux systems. It performs in-depth security scans, identifies vulnerabilities, detects misconfigurations, and provides actionable recommendations to improve your server’s security posture.

Lynis is widely used by:

It is lightweight, agentless, and safe to run on production environments.


Why Use Lynis?

Regular security audits are critical to:

Lynis generates a Hardening Index Score that reflects the overall security level of your system.


Key Features

✔ Agentless and lightweight
✔ No external dependencies
✔ Modular scanning (only scans what exists on the system)
✔ Detailed logging and reporting
✔ Compliance-oriented checks
✔ Suitable for production servers
✔ Supports Linux, macOS, BSD, and Unix systems


Installation Guide

Below are multiple installation methods depending on your environment.


On RHEL / CentOS / AlmaLinux / Rocky Linux

sudo dnf install epel-release -y
sudo dnf install lynis -y

For older systems:

sudo yum install epel-release -y
sudo yum install lynis -y

On Ubuntu / Debian

sudo apt update
sudo apt install lynis -y

Method 2 – Install from Official Source (Latest Version)

This method ensures you get the latest stable release.

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

Run directly:

sudo ./lynis audit system

(Optional) Create a symlink:

sudo ln -s /usr/local/lynis/lynis /usr/local/bin/lynis

Verify installation:

lynis --version

Running a Security Audit

To perform a full system audit:

sudo lynis audit system

During the scan, Lynis will:


Understanding the Output

After completion, Lynis provides:

1. Warnings

Critical issues that should be addressed immediately.

2. Suggestions

Recommended improvements to increase hardening.

3. Hardening Index

Example:

Hardening index : 72 [##############      ]

Higher score = Better security posture.


Report and Log Files

Lynis stores results in:

/var/log/lynis.log
/var/log/lynis-report.dat

These files are useful for:


Fixing Issues (Example)

If Lynis reports SSH weaknesses:

Example recommendation:

Disable password authentication

Fix:

Edit SSH config:

sudo nano /etc/ssh/sshd_config

Set:

PasswordAuthentication no

Restart SSH:

sudo systemctl restart sshd

Re-run audit to verify improvement.


Automating Lynis with Cron

To run daily security scans automatically:

sudo crontab -e

Add:

0 3 * * * /usr/bin/lynis audit system --quiet

This runs the audit every day at 3:00 AM.


Advanced Usage

Run specific test categories

sudo lynis audit system --tests-from-group authentication

Generate report only (no screen output)

sudo lynis audit system --quiet --report-file /root/lynis-custom-report.dat

Production Best Practices

✔ Run Lynis after server deployment
✔ Schedule weekly automated audits
✔ Re-run after major updates
✔ Review Hardening Index trends
✔ Integrate results into monitoring or SIEM


Integrating with Monitoring Systems

You can forward /var/log/lynis.log to:

This allows centralized security tracking across multiple servers.


Security & Compliance Benefits

Using Lynis helps:


When to Run Lynis


Conclusion

Lynis is a powerful and lightweight security auditing tool that helps administrators proactively harden their infrastructure. By incorporating regular Lynis audits into your operational workflow, you significantly reduce security risks and improve system resilience.

For production environments, we strongly recommend automating weekly scans and reviewing the Hardening Index as part of your security baseline management.