Linux Server Hardening: Essential Security Steps

In short: As of September 5, 2026, minimum Linux server hardening means installing security fixes, exposing only essential ports, requiring SSH keys, and monitoring authentication failures. Start with these controls, then adapt the CIS Benchmark to your distribution and the server’s role. Never copy a checklist without testing access and services after each change.
After years of deploying and maintaining Linux servers, I favour a gradual approach. Every measure should reduce the attack surface without disrupting administration or the hosted application.
What is the minimum hardening for a Linux server?
Start by inventorying accounts, active services, and genuinely required ports. Back up configurations before editing them and apply changes one at a time.
The CIS Benchmark for Ubuntu Linux provides a configuration reference produced through a community consensus process. It is not a universal recipe: select the recommendations compatible with the server’s role, then verify their effects.
How should you secure SSH access?
Use SSH keys, prohibit direct root login, and disable passwords only after testing key access in a second session. On Ubuntu, put your settings in a file under /etc/ssh/sshd_config.d/ to keep them separate from the system-provided configuration:
# /etc/ssh/sshd_config.d/99-hardening.conf
PermitRootLogin no
PasswordAuthentication no
Always validate the syntax before restarting the service. Keep the current session open until a new connection succeeds:
sudo sshd -t
sudo systemctl restart ssh.service
Changing the SSH port can reduce bot noise, but it is not a primary protection. The Ubuntu OpenSSH documentation covers configuration files, keys, and the precautions needed to avoid losing access.
How should you restrict exposed services with a firewall?
Apply a restrictive policy, then open only the required services. For an Ubuntu web server administered over SSH:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
sudo ufw status verbose
Adapt these rules to your application before enabling the firewall. The Ubuntu firewall documentation confirms that ufw is Ubuntu’s default interface for a host firewall and explains how to restrict a rule to an address or network.
How can you automate security updates?
On Ubuntu, unattended-upgrades automatically applies security updates and keeps its logs in /var/log/unattended-upgrades:
sudo apt install unattended-upgrades
sudo dpkg-reconfigure -plow unattended-upgrades
Review allowed origins and restart behaviour against your operational constraints. The Ubuntu automatic updates documentation also notes that adding a third-party repository does not automatically include it.
When should you install Fail2ban?
Fail2ban is useful when an exposed service produces usable authentication-failure logs. It can then update firewall rules to block addresses that cause repeated failures:
sudo apt install fail2ban
sudo systemctl enable --now fail2ban
Verify that the jail for your service is actually active and that the expected logs are available. The official Debian Fail2ban package page describes its operation, filters, and support for common firewalls. Fail2ban complements SSH keys and a firewall; it does not replace them.
How do you maintain hardening over time?
Initial hardening loses value without follow-up. Regularly review accounts, open ports, enabled services, pending updates, and authentication alerts. Test backup restoration as well, and document every exception to your security baseline.
Conclusion
Security is an ongoing process. Start with updates, a restrictive firewall, SSH keys, and actionable monitoring. Then add controls that match your server’s data, exposure, and obligations without blindly applying a generic checklist.
Sources
Frequently asked questions
What is the minimum hardening for a Linux server?
Apply security updates, restrict exposed services with a firewall, secure SSH with keys, and monitor login attempts. Then adapt a reference such as the CIS Benchmark to the server’s actual role.
Should you disable SSH passwords?
Yes, if every administrator has a tested key and a recovery path. Validate the configuration and keep your current session open before restarting SSH so that you do not lock yourself out.
Does Fail2ban replace a firewall?
No. A firewall limits which services are reachable, while Fail2ban analyses logs and can block addresses that repeatedly fail authentication. The two protections complement each other.
Is changing the SSH port enough to secure a server?
No. A different port can reduce automated noise, but it does not replace SSH keys, disabled root login, network filtering, or security updates.