Security and hardening · Intermediate · 11 min
How to Audit Your Linux Server's Security with Lynis
By Padding · Updated 15 Nov 2026
Ubuntu 26.04.1 LTS · Lynis 3.1
You will run a Lynis 3.1 security audit on an Ubuntu 26.04 server, read its hardening score and findings, fix one of them, and run it again to see the score move.
On this page
After you harden a server you want proof that it worked, and a way to notice when something drifts. Lynis is an open-source auditing tool. It runs a few hundred checks on the machine it is installed on (SSH settings, file permissions, installed software, kernel settings, firewall state and more) and ends with a hardening score and a list of suggestions. It changes nothing by itself. It only reports.
In this tutorial you will install Lynis, run an audit, learn where the findings are stored, fix one of them, and compare the results. It is a measuring tool. A score of 100 is not the goal, and some suggestions do not suit your server.
Step 1 · Install Lynis
Ubuntu's archive carries Lynis 3.1. The project also publishes its own repository with newer releases, which is worth adding if you want the latest checks. The archive version is enough to learn the tool.
sudo apt-get update
sudo apt-get install -y lynisCheck it worked
lynis show versionThe output is the version number, for example 3.1.6. Lynis may print a notice that its version is more than six months old. That is normal for a packaged release, and it means newer checks exist upstream.
Step 2 · Run the audit
Run the audit with root rights, since many checks read files only root can open. --quick skips the pauses where Lynis waits for you to press Enter between sections. The audit takes a minute or two.
sudo lynis audit system --quick --no-colorsThe output scrolls through sections with names something like Boot and services, Kernel, Users, Groups and Authentication, Software: firewalls and SSH Support. Each check ends in a result in square brackets, such as [ OK ], [ FOUND ], [ NONE ], [ SUGGESTION ] or [ WARNING ]. Without --no-colors, they are green, yellow and red. The summary at the end looks like this:
Lynis security scan details:
Hardening index : 56 [########### ]
Tests performed : 232
Plugins enabled : 1Your numbers will differ with the server, and the layout may differ a little between Lynis versions. Note the hardening index and the number of tests, and write down the index so you can compare it later.
Step 3 · Read the findings
The screen output scrolls away. Lynis saves everything to two files, which you read with sudo:
/var/log/lynis-report.datholds results in a plainkey=valueformat, which is good for searching./var/log/lynis.logholds a detailed log of every test, which is good for finding out why a test gave its result.
Pull out the score and the two lists that matter:
sudo grep '^hardening_index=' /var/log/lynis-report.dat
sudo grep -c '^warning\[\]=' /var/log/lynis-report.dat
sudo grep '^suggestion\[\]=' /var/log/lynis-report.dat | cut -d'|' -f1-2 | head -n 20The first line is the hardening index, a number from 0 to 100. The second counts warnings, which are things Lynis considers wrong. The third lists suggestions as a test ID, such as DEB-0811, then the advice. Handle warnings first, then suggestions.
To see why a test fired and what Lynis found, ask for its details by ID. Use an ID from your own list:
sudo lynis show details DEB-0811The output is the part of lynis.log for that test: what it checked, what it found, and the suggestion it raised. Search the Lynis controls documentation at cisofy.com/lynis/controls/ for the same ID if you want the full explanation.
Troubleshooting
Warning: Lynis is not running as rootor manySkippedtests: you ran it withoutsudo. Run it again withsudo.- The audit stops at each section and waits: you left out
--quick. Press Enter each time, or add the option. - A suggestion does not apply to your server, such as a check for a service you do not run: leave it. You can stop it from appearing by adding
skip-test=DEB-0811(use the real ID) to/etc/lynis/custom.prf. Write down why, so you remember later.
Step 4 · Fix a finding and measure again
Be careful about which suggestions you act on. Do not apply them in bulk. A suggestion that edits the SSH daemon, the firewall or fstab can lock you out or stop the machine from booting. Test each change in the way the related tutorials describe, such as /tutorials/harden-ssh-on-ubuntu-26-04 for SSH, and keep a second session open.
A low-risk fix from a typical list installs a small package. apt-listchanges shows important changes before an upgrade. Install it now:
sudo apt-get install -y apt-listchangesOther suggestions deserve a proper setup rather than a bare install. Lynis will suggest Fail2ban, for example, and the steps for it are in /tutorials/block-brute-force-logins-with-fail2ban. Now run the audit again and compare the results:
sudo lynis audit system --quick --no-colors > /dev/null
sudo grep '^hardening_index=' /var/log/lynis-report.dat
sudo grep -c '^suggestion\[\]=' /var/log/lynis-report.datThe index goes up a little, by a point or two for a change this small, and the suggestion count is lower by one. Test DEB-0811 is no longer in the list:
sudo grep -c 'DEB-0811' /var/log/lynis-report.dat || echo "gone"The output is 0 followed by gone: grep -c prints a count of 0 and exits with an error, which triggers the echo. Each run overwrites /var/log/lynis-report.dat, so copy it to a dated file if you want a history.
sudo cp /var/log/lynis-report.dat "$HOME/lynis-report-$(date +%F).dat"Step 5 · Make it a habit
A server drifts over time. Packages arrive, settings change and services are added. Run the audit after every major change, and once a month in between. Keep the process light:
- Read only the warnings and the new suggestions.
- Fix the ones that matter to you, and mark the rest with
skip-testand a comment. - Treat the hardening index as a trend. A sudden drop after a change tells you the change had a side effect.
For a scheduled run, sudo lynis audit system --cronjob produces no colour or prompts and is meant for cron. Start with the manual routine until you know what a normal result looks like on your servers.
Next steps
- Close ports you do not use:
/tutorials/set-up-ufw-firewall-ubuntu-26-04. - Stop password guessing:
/tutorials/block-brute-force-logins-with-fail2ban. - Patch on its own:
/tutorials/automatic-security-updates-ubuntu. - The project documentation and the list of control IDs are at cisofy.com/lynis.
Related tutorials
- How to Do the Initial Setup of a New Ubuntu 26.04 ServerYou will take a fresh Ubuntu 26.04 server from a root-only login to an updated machine with a daily-use account, your SSH key on it, a firewall and a known clock.
- How to Log In to a Linux Server with SSH KeysYou will create an Ed25519 SSH key, install its public half on a server, log in without a password, and save the connection as a short name.
Need this done for you?
Padding does this work for growing companies, from the first diagnosis to a system that keeps working.
Get new tutorials