Tutorials · Security Operations
How to Harden Linux Servers With CIS Benchmarks and Lynis
Default installs are not secure enough for servers on a business network. Audit with Lynis, apply the most important CIS Benchmark settings and keep them in place.
Before you start
- A Linux server (Ubuntu, Debian, RHEL or compatible)
- sudo access and a console or second session in case SSH settings change
Step by step
Audit the current state
Lynis is a free auditing tool. It lists warnings and suggestions with a hardening index.
sudo apt install -y lynis sudo lynis audit system
Patch automatically
Install security updates automatically and reboot in a maintenance window.
sudo apt install -y unattended-upgrades sudo dpkg-reconfigure -plow unattended-upgrades
Lock down SSH
Key-only logins, no root login, limited users.
PasswordAuthentication no PermitRootLogin no AllowGroups ssh-admins # then: sudo sshd -t && sudo systemctl reload ssh
Turn on the host firewall
Allow only what the server needs.
sudo ufw default deny incoming sudo ufw allow from 10.1.99.0/24 to any port 22 proto tcp sudo ufw allow 443/tcp sudo ufw enable
Remove what you do not use
Every installed service is attack surface. List listening ports and remove unneeded packages.
sudo ss -tulpnLog and watch
Send auth and system logs to your SIEM, and keep time synchronised with NTP.
Re-audit
Run Lynis again and compare the hardening index. Schedule it monthly.
Commands are generic, industry-standard examples. Exact syntax and menu names vary by model and firmware; check your device's manual on the Documentation page.
Pro tips
- Use the CIS Benchmark PDF for your distribution as the reference, and record deliberate exceptions.
- Automate the settings with Ansible so new servers start hardened.
FAQ
Frequently asked questions
Will hardening break applications?
It can. Apply changes on a test server first and change one area at a time.
Keep learning
Related guides
SSH keys instead of passwords
Read more →Automate with Ansible
Read more →Secure Docker containers
Read more →How to Set Up a WireGuard VPN Server for Remote Access
WireGuard is a fast, modern VPN with a small, auditable code base. Build a WireGuard server on Linux, add users with their own keys and route them only to the networks they need.
Read more →How to Scan Your Network for Vulnerabilities With Nmap and OpenVAS
Find open ports, outdated services and known vulnerabilities before attackers do. Discover hosts with Nmap, then run authenticated vulnerability scans with Greenbone OpenVAS and fix what matters first.
Read more →How to Build a Free SIEM With Wazuh for Network and Server Logs
A SIEM collects logs from servers, firewalls and switches in one place and alerts on attacks. Install Wazuh, add agents and syslog sources, and tune the first alerts.
Read more →Stuck on a step?
Ask Navijin technical support or an authorised partner for help with your configuration.