Linux Server Hardening: A Practical Security Checklist

Linux Server Hardening

A fresh Linux server install is functional, not secure. Hardening is the process of removing what you do not need, locking down access, and adding monitoring so that an attacker has far fewer ways in and you notice quickly if something goes wrong. This guide covers the techniques that make the biggest difference, with commands for common distributions.

Quick answer: to harden a Linux server: patch it and enable automatic security updates, use SSH keys and disable root and password logins, run a host firewall that allows only needed ports, add fail2ban, keep SELinux or AppArmor enforcing, remove unused packages and services, enable logging and auditing, and benchmark against the CIS Benchmark for your distribution.

Linux hardening checklist

AreaActionExample
UpdatesPatch now and enable automatic security updatesunattended-upgrades (Debian, Ubuntu) or dnf-automatic (RHEL family)
SSHKey-based login only, no root loginPermitRootLogin no and PasswordAuthentication no in sshd_config
Brute forceBan repeated failed loginsfail2ban
FirewallDefault deny, allow only required portsufw, firewalld or nftables
Mandatory access controlKeep it enforcingSELinux (RHEL family) or AppArmor (Ubuntu, Debian)
Attack surfaceRemove unused packages and stop unused servicessystemctl list-unit-files –state=enabled
PrivilegesUse sudo with named accounts, no shared root passwordSeparate admin accounts per person
Logging and auditCentral logs and file change auditingjournald forwarding, auditd
AssessmentScan for weaknesses regularlyLynis, CIS Benchmarks
network security measures for Linux servers

Lock down SSH first

  1. Create a named admin user with sudo rights.
  2. Add your SSH public key to that user and test logging in.
  3. In /etc/ssh/sshd_config set PermitRootLogin no and PasswordAuthentication no.
  4. Restart the SSH service, and keep your current session open until you have tested a new login.
  5. Allow SSH only from trusted networks or through a VPN where possible.
Watch out: always test a new SSH login in a second window before closing your current session. A typo in sshd_config or a missing key can lock you out of a remote server.
Pro tip: on a physical server, iDRAC or iLO gives you a remote console even if SSH or the network configuration breaks, which makes hardening changes much less risky. Keep that management interface on a separate, restricted network.

Go further

  • Mount /tmp with noexec and nosuid where your applications allow it.
  • Disable unused kernel modules and protocols.
  • Use full-disk encryption (LUKS) for servers that hold sensitive data.
  • Monitor integrity of key files with AIDE or a similar tool.
  • Back up and test restores, because hardening reduces risk but never removes it.
Good to know: the Center for Internet Security publishes free CIS Benchmarks for major Linux distributions. They are a widely used checklist for auditors and a good way to check your work.

Related reading: zero trust for servers, refurbished server security and firmware updates, because hardware firmware needs patching too.

Frequently asked questions

What is Linux server hardening?

It is reducing a Linux server’s attack surface and strengthening its defences through updates, access control, firewalls, service removal, logging and auditing.

Should I disable root login over SSH?

Yes. Log in as a named user with SSH keys and use sudo for admin tasks. It improves security and accountability.

Is fail2ban still useful with SSH keys?

Yes. It blocks repeated attempts against SSH and other services, reducing noise and load, though key-only login is the main protection.

How do I check how secure my Linux server is?

Run an audit tool such as Lynis and compare your configuration against the CIS Benchmark for your distribution.

Need a server to build on? Browse our refurbished servers or contact our team.

Server Site