Harden your systems with Lynis
Starting Your Security Scan
After confirming by pressing the Enter key, Lynis starts its tests and writes the results to your standard output. Results marked in green are the successfully completed tests; red warnings point to problems or vulnerabilities (Figure 2). Administrators simply need to make a note of gray result messages. They show that, for instance, the service is not installed on the system. Messages highlighted in yellow do not point to critical problems, but Lynis does see some scope for improvement. The tool might even suggest some remedies, which appear right at the end of the test report (Figure 3).
![](/var/linux_magazin/storage/images/issues/2016/182/system-hardening-with-lynis/figure-2/662634-1-eng-US/Figure-2_large.png)
![](/var/linux_magazin/storage/images/issues/2016/182/system-hardening-with-lynis/figure-3/662637-1-eng-US/Figure-3_large.png)
After each test, Lynis stops, thus giving the user the opportunity to inspect the output. The test continues after you press the Enter key. If you want Lynis to simply perform all the tests in succession, just add the --quick
or -Q
parameter to the command line. Depending on your terminal, the output from Lynis may use problematic color schemes, or it might be difficult to read. You can stipulate the additional --reverse-colors
parameter to tell Lynis to adapt the colors for a light background. If this doesn't help, you can also completely disable colors by stipulating the --no-colors
parameter.
Lynis consists of a collection of shell scripts, each of which checks precisely one system component. For their work, the scripts harness the power of typical system commands. For example, one of the scripts tests the firewall rules by running iptables. You might find that programs cannot be executed – either because of a program error or because the required access privileges for executing the program are missing. Lynis then deems the test to have failed and issues a warning. You can see an example of this behavior in Figure 2, where access to D-Bus failed. Administrators thus always need to check whether Lynis really has found a problem or whether the test was canceled. It makes sense to check out the error message that appears below the test.
When finished, Lynis delivers some statistics, as shown in Figure 4. You will find a somewhat more exhaustive test report in the /var/log/lynis.log
file. Its counterpart, /var/log/lynis-report.dat
, contains a summary of the test run and the improvements suggested by Lynis. But caution is advisable: as soon as you launch Lynis the next time, it will overwrite the existing logfile and report file.
![](/var/linux_magazin/storage/images/issues/2016/182/system-hardening-with-lynis/figure-4/662640-1-eng-US/Figure-4_large.png)
Automated Scans
To identify problems that have crept in the back door, administrators will want to run Lynis regularly. The --cronjob
option will help you execute the program on a regular schedule: If you run the tool with this parameter, it does not wait for user input and also removes all critical characters (special chars) from the input. In this way, you can run Lynis as a Cron job. Of course, the tool would overwrite the logfile and report file, /var/log/lynis.log
and /var/log/lynis-report.dat
, in each run. You can prevent Lynis from overwriting the logfiles by running Cron using a self-programmed wrapper script. Listing 1 contains a simple example. In the extras/systemd
subdirectory of the Lynis archive, you will also find two files for Systemd: You can use the service
file to enable Lynis automatically on system startup; The timer
file launches the tool once a day. In both cases, it makes sense to copy Lynis to a directory such as /usr/local/lynis
.
Listing 1
Integrating Lynis with Cron
#!/bin/sh DATE=$(date +%Y%m%d) # Launch Lynis: /usr/local/lynis/lynis -c --cronjob > /var/log/lynis-output.${DATE}.txt # Back up generated log files: mv /var/log/lynis.log /var/log/lynis.${DATE}.log mv /var/log/lynis-report.dat /var/log/lynis-report.${DATE}.dat
Using Individual Scans
If so desired, Lynis will also perform predefined tests. The approach is somewhat convoluted, however: Each test has a unique, cryptic ID. For example, Lynis refers to the test against the iptables kernel module as FIRE-4511
. To find out which ID belongs to which test, let Lynis perform all the tests once, and then take a look at the /var/log/lynis.log
file. It lists the IDs to match the tests.
Another source of information are the shell scripts in the include
subdirectory whose filenames start with test_
. The scripts contain the tests themselves; for example the tests_firewall
script groups all the tests relating to the firewall. The test IDs are included as comments in the script. Once you have determined the IDs for the desired tests, add them as a blank-separated list following the --tests
parameter. As an example, the following command would execute the FIRE-4511
and AUTH-9226
tests:
./lynis -Q --tests "FIRE-4511 AUTH-9226"
« Previous 1 2 3 Next »
Buy this article as PDF
(incl. VAT)
Buy Linux Magazine
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Subscribe to our ADMIN Newsletters
Support Our Work
Linux Magazine content is made possible with support from readers like you. Please consider contributing when you’ve found an article to be beneficial.
![Learn More](https://www.linux-magazine.com/var/linux_magazin/storage/images/media/linux-magazine-eng-us/images/misc/learn-more/834592-1-eng-US/Learn-More_medium.png)
News
-
NVIDIA Released Driver for Upcoming NVIDIA 560 GPU for Linux
Not only has NVIDIA released the driver for its upcoming CPU series, it's the first release that defaults to using open-source GPU kernel modules.
-
OpenMandriva Lx 24.07 Released
If you’re into rolling release Linux distributions, OpenMandriva ROME has a new snapshot with a new kernel.
-
Kernel 6.10 Available for General Usage
Linus Torvalds has released the 6.10 kernel and it includes significant performance increases for Intel Core hybrid systems and more.
-
TUXEDO Computers Releases InfinityBook Pro 14 Gen9 Laptop
Sporting either AMD or Intel CPUs, the TUXEDO InfinityBook Pro 14 is an extremely compact, lightweight, sturdy powerhouse.
-
Google Extends Support for Linux Kernels Used for Android
Because the LTS Linux kernel releases are so important to Android, Google has decided to extend the support period beyond that offered by the kernel development team.
-
Linux Mint 22 Stable Delayed
If you're anxious about getting your hands on the stable release of Linux Mint 22, it looks as if you're going to have to wait a bit longer.
-
Nitrux 3.5.1 Available for Install
The latest version of the immutable, systemd-free distribution includes an updated kernel and NVIDIA driver.
-
Debian 12.6 Released with Plenty of Bug Fixes and Updates
The sixth update to Debian "Bookworm" is all about security mitigations and making adjustments for some "serious problems."
-
Canonical Offers 12-Year LTS for Open Source Docker Images
Canonical is expanding its LTS offering to reach beyond the DEB packages with a new distro-less Docker image.
-
Plasma Desktop 6.1 Released with Several Enhancements
If you're a fan of Plasma Desktop, you should be excited about this new point release.