Skip to content
Back to Cloud Services

Lynis: audit and harden a Linux server's security posture

Run Lynis for a 5-minute security audit that scores the server and lists specific hardening suggestions.

Server SecurityBeginner

Why

Lynis is a single-shell-script auditor that checks 200+ items (SSH config, permissions, kernel params, services) and outputs a hardening index plus actionable suggestions — far cheaper than a pentest for baseline hardening. Verizon's 2024 DBIR shows 68% of breaches involve a non-malicious human element.

SSH key compromise and misconfigured S3 buckets are top attack vectors — hardening reduces breach risk by 80%+.

When

Run on every new server after initial setup, before each compliance audit, and monthly as a drift check. Avoid security theater (obscurity without depth) — a non-standard SSH port stops 0 real attacks.

Skip heavy WAF rules if you have no known vulnerabilities; they add latency and false positives.

How

1. Install: `apt install lynis` or download the latest from cisofy.io. 2. Run a full audit: `lynis audit system` (writes to /var/log/lynis.log and /var/log/lynis-report.dat). 3. View suggestions: `lynis show suggestions`. 4. View tests: `lynis show tests`. 5. Set a profile to skip noisy tests: copy /etc/lynis/default.prf to /etc/lynis/custom.prf, add skip-test=TIME-1234. 6. Re-run: `lynis audit system --profile custom.prf`. 7. The hardening index appears at the end; target 80+ for a web server, 90+ for a bastion.

Example

# Install and run apt install lynis lynis audit system --quick # faster, fewer tests # Or full audit with colored output lynis audit system # Review the report grep -E 'Suggestion|Warning' /var/log/lynis.log # Show the hardening index tail -20 /var/log/lynis.log | grep -i 'hardening index' # Custom profile to skip a noisy test cp /etc/lynis/default.prf /etc/lynis/custom.prf echo 'skip-test=SSH-7408' >> /etc/lynis/custom.prf lynis audit system --profile /etc/lynis/custom.prf

Common Problems

  • ⚠Lynis flags 100+ warnings on a default install — fix the high-severity ones first, accept some as documented exceptions.
  • ⚠Running as non-root skips many tests — run as root for a complete audit.
  • ⚠Hardening index doesn't improve after fixes — re-run with --quick to refresh the cache, or check the log for errors.

Best Practices

  • ✓Run Lynis in CI on your base image (Packer/Ansible) so hardening is baked in, not applied per-server.
  • ✓Track the hardening index over time; alert if it drops (someone added a weak service or changed a perm).
  • ✓Document accepted warnings in a exceptions file with a reason and reviewer — auditors accept justified exceptions.

FAQ

What is Lynis: audit and harden a Linux server's security posture and what problem does it solve?

Run Lynis for a 5-minute security audit that scores the server and lists specific hardening suggestions. It lets developers deploy, store, and scale without self-managing infrastructure — a core reference for cloud service selection.

How do I get started with Lynis: audit and harden a Linux server's security posture in 5 minutes?

Two steps to run it: (1) Install: `apt install lynis` or download the latest from cisofy.io.; (2) Run a full audit: `lynis audit system` (writes to /var/log/lynis.log and /var/log/lynis-report.dat).. Validate on the free tier first, then wire into production.

What is the #1 pitfall with Lynis: audit and harden a Linux server's security posture?

The most frequent issue is: Lynis flags 100+ warnings on a default install — fix the high-severity ones first, accept some as documented exceptions.. Run a pre-launch checklist item by item, and add policy/config scanning in CI.

What are the best practices for Lynis: audit and harden a Linux server's security posture?

Best practices for Lynis: audit and harden a Linux server's security posture include: Run Lynis in CI on your base image (Packer/Ansible) so hardening is baked in, not applied per-server.; Track the hardening index over time; alert if it drops (someone added a weak service or changed a perm).; Document accepted warnings in a exceptions file with a reason and reviewer — auditors accept justified exceptions.. The first one — "Run Lynis in CI on your base image (Packer/Ansible) so hardening is baked in, not applied per-server." — should be a team default baked into your IaC templates.

How do I control cost and avoid bill surprises with Lynis: audit and harden a Linux server's security posture?

Three ways to prevent overspend: (1) tag every resource with env/team and enable billing alarms; (2) set budget thresholds to trigger Slack/email alerts; (3) review idle resources in Cost Explorer regularly and clean them up. Most Lynis: audit and harden a Linux server's security posture options offer a free tier — validate within free quota before scaling.