Lynis Explained: How to Audit and Harden Linux Systems
Lynis is a free, open source security auditing tool for Linux, macOS and Unix systems. It runs hundreds of checks on a host, covering boot settings, authentication, file permissions, services, firewall, logging, kernel parameters and installed software, and produces warnings, suggestions and a "hardening index" score.
Topic: Linux Administration in IT Infrastructure · Tutorial
Also covers: Cybersecurity Foundations
Quick answer: Lynis is a free, open source security auditing tool for Linux, macOS and Unix systems. It runs hundreds of checks on a host, covering boot settings, authentication, file permissions, services, firewall, logging, kernel parameters and installed software, and produces warnings, suggestions and a "hardening index" score. Install it from your package manager or GitHub, run sudo lynis audit system, fix the warnings first, then work through suggestions and rescan. It is a quick way to find hardening gaps, but its score is a guide, not proof of compliance with a standard such as the CIS Benchmarks.
Key takeaways
- Lynis runs locally, needs no agent, and does not change the system.
- Fix warnings first; suggestions are lower priority improvements.
- The hardening index helps track progress over time.
- Use OpenSCAP or CIS-CAT for formal benchmark compliance.
- Automate regular scans and compare results.
Table of Contents
- What Does Lynis Check?
- How Do You Install Lynis?
- How Do You Run an Audit?
- How Do You Read the Results?
- How Do You Fix Common Findings?
- How Do You Automate Lynis?
- How Does Lynis Compare with Other Tools?
- References
What Does Lynis Check?
| Area | Examples |
|---|---|
| Boot and kernel | Bootloader password, sysctl hardening |
| Authentication | Password policies, PAM, sudo configuration |
| SSH | Root login, password authentication, ciphers |
| File systems | Mount options, world-writable files, SUID binaries |
| Services and software | Unnecessary services, outdated packages |
| Firewall and networking | Active firewall, open ports |
| Logging and auditing | syslog, auditd |
| Malware and integrity | Presence of tools such as AIDE or rkhunter |
How Do You Install Lynis?
# Debian/Ubuntu
sudo apt install lynis
# RHEL/Fedora (EPEL may be needed on RHEL)
sudo dnf install lynis
# Latest version from GitHub (no installation needed)
git clone https://github.com/CISOfy/lynis
cd lynis && sudo ./lynis audit system
Distribution packages can lag behind; the GitHub version has the newest tests.
How Do You Run an Audit?
sudo lynis audit system # full local audit
sudo lynis audit system --quick # no pauses between sections
sudo lynis show details SSH-7408 # explain a specific test
How Do You Read the Results?
- Warnings: likely security issues; address first.
- Suggestions: improvements; evaluate each for your environment.
- Hardening index: a 0 to 100 score summarising results.
- Files: detailed log in
/var/log/lynis.logand machine-readable data in/var/log/lynis-report.dat.
sudo grep -E "^warning|^suggestion" /var/log/lynis-report.dat | head -20
sudo grep hardening_index /var/log/lynis-report.dat
How Do You Fix Common Findings?
| Finding | Fix |
|---|---|
| SSH allows root login or passwords | Set PermitRootLogin no and PasswordAuthentication no after setting up keys |
| No firewall active | Enable firewalld, UFW or nftables with default deny |
| auditd not running | sudo systemctl enable --now auditd |
| Packages need updates | Run updates and enable automatic security updates |
| Weak sysctl settings | Set values such as net.ipv4.conf.all.accept_redirects=0 in /etc/sysctl.d/ |
Re-run Lynis after each round of fixes and record the hardening index.
How Do You Automate Lynis?
# /etc/cron.weekly/lynis (make executable)
#!/bin/sh
/usr/sbin/lynis audit system --cronjob --quiet
cp /var/log/lynis-report.dat /var/log/lynis-report-$(date +%F).dat
Send results to your log platform to track trends across servers.
How Does Lynis Compare with Other Tools?
| Tool | Strength |
|---|---|
| Lynis | Fast, broad hardening review with practical suggestions |
| OpenSCAP | Formal compliance profiles (CIS, DISA STIG) and remediation scripts |
| CIS-CAT | Official scoring against CIS Benchmarks |
| Vulnerability scanners | Missing patches and known CVEs |
See NIST SP 800-123 for server security principles and our Linux server hardening guide. WebAsha offers Linux security training.
References
Frequently Asked Questions
What's Your Reaction?
Like
1
Dislike
0
Love
0
Funny
0
Wow
0
Sad
0
Angry
0