You launch an audit before going into production, and Lynis raises a long list of warnings. The score catches the eye, but applying each suggestion in order could break SSH access, a business service, or a backup.
On a test Debian, Ubuntu, or Rocky server, Lynis helps identify settings to check. The proper use consists of reading the test, relating the recommendation to the server’s role, and then correcting one measurable point at a time.
Prepare the audit on a known scope
Install Lynis from your distribution’s repositories when the package is available. On Debian or Ubuntu, the installation uses APT. On Rocky Linux or RHEL, the package name and availability may depend on the activated repositories.
sudo apt update
sudo apt install lynis
lynis show version
Before the audit, keep the configuration of services that expose the server, especially SSH, the firewall, and backups. A VM snapshot or a versioned copy of /etc simplifies the rollback if a recommendation changes an expected behavior.
Also, take inventory of the machine’s role. A web host, a backup server, and a lab VM do not accept the same restrictions. The Lynis score does not recognize your application flows or your internal policy.
Read the Lynis report without following each suggestion
Run the complete audit with the necessary privileges. Lynis writes its results in its log and report, typically under /var/log/lynis.log and /var/log/lynis-report.dat.
sudo lynis audit system
sudo less /var/log/lynis.log
sudo grep '^suggestion=' /var/log/lynis-report.dat
Each suggestion must go through three questions: what test produced it, which file or service would be modified, and what control will prove that the server is still functioning after the change? This sorting avoids confusing a general good practice with a requirement tailored to your machine.
- A SSH-related alert concerns administrative access. Keep a second connection open before any changes to
sshd_config. - A recommendation on permissions targets a specific path. Check the owner and the service that uses it before a
chmod. - A kernel or module suggestion requires a maintenance window, as a reboot may be necessary.
The Lynis documentation explains the commands, profiles, and report files. It serves to understand the raised test, not to impose identical configurations across all servers.
Fix a setting and then rerun the check
Choose a low-impact recommendation and document the initial state. For example, before reducing a file’s permissions, note the owner, group, and processes that open it.
sudo stat /path/to/the/file
sudo lsof /path/to/the/file
sudo systemctl status service-name --no-pager
Then apply the selected correction, test the service, and rerun Lynis. The report should show the disappearance or evolution of the relevant test. If the service fails, restore the backed-up configuration instead of adding a second change to bypass the first.
sudo systemctl restart service-name
sudo systemctl status service-name --no-pager
sudo lynis audit system
Use the score as a reference, not as a goal
A higher score often indicates additional checks, but it does not prove that a server is suited to its workload or protected against every risk. A rule applied without knowing the application can improve the score and disrupt a necessary flow.
I would start with the results that correspond to a truly exposed service, then check each change in the log and with the relevant service. This method takes more time than a series of copied commands, but it leaves you with a system whose compromises you understand.
Keep the report before and after the intervention. It is useful during the next update or when another administrator needs to understand why a setting was chosen.