Security

Audit Linux VPS security with Lynis

Install Lynis, run a security audit on a Linux VPS, read the hardening index, warnings and suggestions, fix the most important findings and schedule regular audits.

IntermediateLinux VPS2 min read

Lynis is a free, open-source auditing tool that checks hundreds of Linux settings and reports weaknesses with concrete suggestions. Running a Lynis security audit after setting up a VPS is a quick way to see what you missed.

Before you start

Install Lynis

sudo apt install -y lynis

AlmaLinux/Rocky: install from EPEL (sudo dnf install -y epel-release && sudo dnf install -y lynis). Distribution packages can lag behind; the CISOfy repository or a Git clone gives the latest version.

Run an audit

sudo lynis audit system

The scan takes a minute or two and prints results by section: boot, kernel, users, SSH, networking, firewall, file permissions, logging and more.

Read the results

  • Hardening index: a score out of 100. Use it to track progress, not as a goal in itself.
  • Warnings: important problems to fix first.
  • Suggestions: improvements, each with a test ID (e.g. SSH-7408) and a link to details.

The full report is saved to /var/log/lynis-report.dat and the log to /var/log/lynis.log. List suggestions:

sudo grep suggestion /var/log/lynis-report.dat

Common findings and fixes

FindingFix
SSH allows password or root loginKeys only; see SSH lockdown checklist
No firewall activeEnable UFW or firewalld
No brute-force protectionInstall fail2ban
Pending security updatesEnable automatic security updates
Unused services listeningDisable with systemctl disable --now
No file integrity or auditing toolsConsider AIDE or auditd for sensitive servers
Weak kernel/sysctl settingsReview suggested sysctl values before applying

Skip tests that do not apply

Create /etc/lynis/custom.prf and add lines like skip-test=FILE-6310 for checks that are irrelevant to your setup (for example separate partitions on a small VPS).

Schedule regular audits

0 4 * * 0 /usr/sbin/lynis audit system --cronjob > /var/log/lynis-cron.log 2>&1

Add it to root's crontab and review the score weekly; see cron jobs guide.

Frequently asked questions

Does Lynis change my system?

No, it only reads and reports. You apply fixes yourself.

What score is good?

There is no universal target. Fix warnings and the suggestions relevant to your services.

Should I apply every suggestion?

No. Some conflict with your workload; understand each change first.

Next steps

Was this guide helpful?

Still stuck?

Ask MdmHost AI for a quick answer, or open a ticket and our team will take a look. We are here 24/7.