VOOZH about

URL: https://thenewstack.io/lynis-run-a-security-audit-on-linux-for-free/

⇱ Lynis: Run a Security Audit on Linux for Free - The New Stack


TNS
SUBSCRIBE
Join our community of software engineering leaders and aspirational developers. Always stay in-the-know by getting the most important news and exclusive content delivered fresh to your inbox to learn more about at-scale software development.
REQUIRED
It seems that you've previously unsubscribed from our newsletter in the past. Click the button below to open the re-subscribe form in a new tab. When you're done, simply close that tab and continue with this form to complete your subscription.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.
Welcome and thank you for joining The New Stack community!
Please answer a few simple questions to help us deliver the news and resources you are interested in.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Great to meet you!
Tell us a bit about your job so we can cover the topics you find most relevant.
REQUIRED
REQUIRED
REQUIRED
REQUIRED
REQUIRED
Welcome!

We’re so glad you’re here. You can expect all the best TNS content to arrive Monday through Friday to keep you on top of the news and at the top of your game.

What’s next?

Check your inbox for a confirmation email where you can adjust your preferences and even join additional groups.

Follow TNS on your favorite social media networks.

Become a TNS follower on LinkedIn.

Check out the latest featured and trending stories while you wait for your first TNS newsletter.

PREV
1 of 2
NEXT
VOXPOP
As a JavaScript developer, what non-React tools do you use most often?
Angular
0%
Astro
0%
Svelte
0%
Vue.js
0%
Other
0%
I only use React
0%
I don't use JavaScript
0%
Thanks for your opinion! Subscribe below to get the final results, published exclusively in our TNS Update newsletter:
NEW! Try Stackie AI
From clobbered drafts to real-time sync
Apr 14th 2026 10:00am, by David Moore
TypeScript 6.0 RC arrives as a bridge to a faster future
Mar 14th 2026 9:00am, by Darryl K. Taft
Mastra empowers web devs to build AI agents in TypeScript
Jan 28th 2026 11:00am, by Loraine Lawson
2023-10-28 06:00:40
Lynis: Run a Security Audit on Linux for Free
tutorial,
Containers / Linux / Security

Lynis: Run a Security Audit on Linux for Free

This article walks through the steps of installing Lynis security auditing software on both Ubuntu Server and Rocky Linux 9.
Oct 28th, 2023 6:00am by Jack Wallen
👁 Featued image for: Lynis: Run a Security Audit on Linux for Free
Feature image by Mike Goad from Pixabay.

When developing for cloud or containers, you know you’re probably going to be working with Linux, UNIX, or some similar operating system. When that’s the case, you should also know how imperative that the OS be as secure as possible. After all, with the numerous moving parts of containers and the cloud, if your foundation is weak, everything could crumble.

That means you need to know the ins and outs and minutia of those platforms, especially regarding security.

The problem can be if you’re coming from either a MacOS or Windows background and you’re unfamiliar with Linux. That’s when a tool like Lynis comes in handy.

Lynis simplifies the security audits for operating systems such as:

  • AIX
  • FreeBSD
  • HP-UX
  • Linux
  • macOS
  • NetBSD
  • NixOS
  • OpenBSD
  • Solaris

With Lynis, you can perform tasks like:

  • Security auditing
  • Compliance testing
  • Penetration testing
  • Vulnerability detection
  • System hardening

Lynis is also opportunistic, which means it will only use and test components within an OS that it discovers. In other words, if a component isn’t installed on your OS, Lynis won’t test for it. Lynis is also quite easy to install and use for system auditing, which is something you should be doing for every OS you use for cloud and container development and/or deployment.

I’m going to walk you through the steps of installing Lynis on both Ubuntu Server and Rocky Linux 9. Once installed, we’ll run security audits to see what’s what. The good news is that the auditing process is the same, regardless of the OS.

👁 Image

What You Need

To install and use Lynis, you’ll need either a running instance of Ubuntu Server (I’m using v22.04) or Rocky Linux (v9). You’ll also need a user with sudo privileges.

That’s all you need. Let’s get to the installation.

Installing Lynis

The installation of Lynis on both Ubuntu Server and Rocky Linux is similar.

To install Lynis on Ubuntu Server, the command is:

sudo apt-get install lynis -y

The command to install Lynis on Rocky Linux (or another RHEL clone), the command is:

sudo dnf install lynis -y

If you don’t want to fully install Lynis, you can do the following:

  1. Download the source from the official Lynis download page.
  2. Extract the downloaded file with the command tar xvzf lynix-XXX.tar.gz (where XXX is the release number).
  3. Change into the newly created directory with the command cd lynis.

Running a Security Audit with Lynis

We can now run our first security audit with Lynis. The basic command for the audit is:

sudo lynis audit system

You need to run the lynis command with sudo, otherwise you miss out on a number of checks. If you are using Lynis from source, the same command would be (run from within the lynis directory):

sudo ./lynis audit system

The command will execute all of the checks (based on what’s installed on the system) and will report (in most cases) considerable output, which will look something like this:

* Determine if protocol ‘tipc’ is really needed on this system [NETW-3200]
https://cisofy.com/lynis/controls/NETW-3200/
* Install Apache mod_evasive to guard webserver against DoS/brute force attempts [HTTP-6640]
https://cisofy.com/lynis/controls/HTTP-6640/
* Install Apache modsecurity to guard webserver against web application attacks [HTTP-6643]
https://cisofy.com/lynis/controls/HTTP-6643/
* Consider hardening SSH configuration [SSH-7408]
– Details  : AllowTcpForwarding (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : ClientAliveCountMax (set 3 to 2)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : Compression (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : LogLevel (set INFO to VERBOSE)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : MaxAuthTries (set 6 to 3)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : MaxSessions (set 10 to 2)
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : Port (set 22 to )
https://cisofy.com/lynis/controls/SSH-7408/
* Consider hardening SSH configuration [SSH-7408]
– Details  : TCPKeepAlive (set YES to NO)
https://cisofy.com/lynis/controls/SSH-7408/

As you can see, when Lynis finds a possible issue, it will offer a suggestion by way of a link. Open any one of those links to read a description of how to mitigate the issue.

One caveat to using Lynis is the output can be fairly lengthy. If you’re on a headless server (or using it via a remote cloud host), you might not have the ability to scroll through the output. Fortunately, Lynis also writes to a log file at /var/log/lynis.log. You can view the log file with the command:

sudo less /var/log/lynis.log

Scroll through the file to see if you find anything that must be taken care of immediately.

Keep in mind, however, that each time you run Lynis it will overwrite the log file. So make sure you either rename the previous log file (if you’ve not read through it) or move it. You can rename it with a command like:

sudo mv /var/log/lynis.log /var/log/lynis.log.old

You’ll probably find that Lynis reports that a lot needs to be done to harden your server, which can be rather daunting. Go through the Lynis log file, line by line, and mitigate anything you deem necessary and your server will thank you by being considerably more secure than it was prior to using this tool.

Just remember, Lynis doesn’t fix things for you, it simply lets you know what needs to be addressed.

TRENDING STORIES
Jack Wallen is what happens when a Gen Xer mind-melds with present-day snark. Jack is a seeker of truth and a writer of words with a quantum mechanical pencil and a disjointed beat of sound and soul. Although he resides...
Read more from Jack Wallen
SHARE THIS STORY
TRENDING STORIES
SHARE THIS STORY
TRENDING STORIES
TNS DAILY NEWSLETTER Receive a free roundup of the most recent TNS articles in your inbox each day.
The New Stack does not sell your information or share it with unaffiliated third parties. By continuing, you agree to our Terms of Use and Privacy Policy.