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.
Linux hardening checklist
| Area | Action | Example |
|---|---|---|
| Updates | Patch now and enable automatic security updates | unattended-upgrades (Debian, Ubuntu) or dnf-automatic (RHEL family) |
| SSH | Key-based login only, no root login | PermitRootLogin no and PasswordAuthentication no in sshd_config |
| Brute force | Ban repeated failed logins | fail2ban |
| Firewall | Default deny, allow only required ports | ufw, firewalld or nftables |
| Mandatory access control | Keep it enforcing | SELinux (RHEL family) or AppArmor (Ubuntu, Debian) |
| Attack surface | Remove unused packages and stop unused services | systemctl list-unit-files –state=enabled |
| Privileges | Use sudo with named accounts, no shared root password | Separate admin accounts per person |
| Logging and audit | Central logs and file change auditing | journald forwarding, auditd |
| Assessment | Scan for weaknesses regularly | Lynis, CIS Benchmarks |

Lock down SSH first
- Create a named admin user with sudo rights.
- Add your SSH public key to that user and test logging in.
- In /etc/ssh/sshd_config set PermitRootLogin no and PasswordAuthentication no.
- Restart the SSH service, and keep your current session open until you have tested a new login.
- Allow SSH only from trusted networks or through a VPN where possible.
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.
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.


