Linux Hardening
Linux is everywhere - web servers, cloud infrastructure, containers, embedded devices, developer workstations. And because it’s so prevalent, it’s also a top target. The good news is that Linux gives you a lot of control over your security posture. The bad news is that control only helps if you actually use it. This page covers the practical hardening steps you should apply to any Linux system, whether it’s a production server, a cloud VM, or a dev box handling sensitive work.Where to Start - The CIS Benchmark
Before doing anything manual, grab the CIS Benchmark for your distribution. CIS maintains specific benchmarks for:- Ubuntu (LTS versions)
- Red Hat Enterprise Linux / CentOS / AlmaLinux
- Debian
- SUSE Linux Enterprise
- Amazon Linux
User and Authentication Hardening
Disable the Root Login (or Restrict It Heavily)
If root is accessible directly, you’re one credential leak away from a full system compromise.Enforce Strong Password Policies
Edit/etc/security/pwquality.conf:
/etc/login.defs:
Audit Existing Users and Groups
Configure sudo Properly
Never give blanketALL=(ALL) NOPASSWD: ALL to regular accounts. Edit via visudo:
SSH Hardening
SSH is the most common remote access method - and one of the most targeted services. Lock it down. Edit/etc/ssh/sshd_config:
Firewall Configuration
UFW (Ubuntu / Debian)
firewalld (RHEL / CentOS / Fedora)
File System and Permissions
Set noexec, nodev, nosuid on Appropriate Partitions
Edit/etc/fstab to add mount options:
Find World-Writable Files and SUID/SGID Binaries
Restrict /etc/cron.* Access
Kernel Hardening (sysctl)
Kernel parameters significantly impact security posture. Edit/etc/sysctl.conf or drop files in /etc/sysctl.d/:
Audit Logging (auditd)
auditd is the Linux kernel’s audit framework - essential for monitoring and forensics.
/etc/audit/audit.rules:
Services - Disable What You Don’t Need
avahi-daemon(mDNS/zeroconf - usually not needed on servers)cups(printing - almost never needed on servers)bluetoothrpcbind(only needed for NFS)nfs(unless you’re using NFS)telnet/rsh/rlogin(never use these)
Package Management Security
AppArmor and SELinux
These are Mandatory Access Control (MAC) systems that restrict what programs can do, even if they’re compromised.- AppArmor - Default on Ubuntu/Debian. Usually easier to work with.
- SELinux - Default on RHEL/CentOS/Fedora. More powerful, steeper learning curve.
Useful Tools for Linux Hardening
Quick Wins - Things to Do First
If you’re hardening a Linux server and don’t know where to start, do these first:- Update all packages
- Disable root SSH login
- Switch to key-based SSH authentication
- Enable and configure UFW or firewalld
- Disable unused services
- Enable auditd
- Run Lynis and address the top findings
Reference
- CIS Ubuntu Linux Benchmark
- Lynis - Quick security audit for any Linux system
- DISA STIG for Red Hat - Government-grade hardening
- Linux Audit Documentation - RHEL security hardening guide
There’s no such thing as a fully hardened system - only systems that are harder to attack than others. The goal is to make exploitation as difficult and noisy as possible.
