A new Linux server is exposed to the internet within minutes of going online. Automated scanners probe it for open ports, weak passwords, and outdated software, often before you have finished your first login. If the server is not hardened, it is only a matter of time before someone finds a way in.
Hardening means reducing your server’s attack surface: removing what you do not need, locking down what you do, and monitoring everything else. This Linux server hardening checklist gives you 25 practical steps, grouped by theme, that you can apply to Ubuntu, Debian, AlmaLinux, Rocky Linux, and similar distributions. Follow them in order, and you will have a server that is far harder to compromise.
Linux server hardening is the process of securing a server by minimizing its attack surface, enforcing strong authentication, restricting network access, applying updates, and monitoring for suspicious activity.
The most important actions are:
- Keep the system and its software updated.
- Use SSH keys instead of passwords, and disable direct root login.
- Allow only the network ports you need through a firewall.
- Install fail2ban to block repeated login attempts.
- Run only the services you need, with the least privilege possible.
- Log, audit, and back up everything.
Before you begin: Always keep a second SSH session open while changing SSH or firewall settings. A single typo can lock you out. Test every change on a staging server first when possible.
Why Server Hardening Matters
Most server breaches are not sophisticated. Attackers rely on a short list of weaknesses: unpatched software, weak or reused passwords, exposed management services, and misconfigured permissions. Automated bots try these weaknesses on every public IP address around the clock. A server with default settings and an open SSH port will typically record thousands of failed login attempts within days.
The consequences of a breach go well beyond one machine. An attacker who controls your server can steal customer data, install cryptominers, send spam from your IP address, host phishing pages, launch attacks on other networks, or encrypt your files for ransom. Cleaning up after an incident costs far more time and money than the few hours needed to harden a server properly.
Who should use this checklist?
This guide is written for system administrators, developers who manage their own VPS, and hosting customers who have root access. You do not need to be a security specialist. Each step explains what to do and why it matters, and the commands are suitable for the most common Debian-based and RHEL-based distributions.
How hardening fits into a wider strategy
Hardening is the foundation, not the whole building. Alongside it, you need a web application firewall for public sites, DDoS protection if you are a likely target, and a tested server backup strategy. Think of hardening as making the server hard to break into, and everything else as limiting the damage if someone succeeds.
VPS Server Plans
Explore IT4INT VPS server plans for reliable, high-performance hosting with fast SSD storage, Linux and Windows OS options, full root access, scalable resources, and 24/7 technical support. Choose a VPS hosting plan that fits your website, application, or business needs.
Part 1: Updates and Software Hygiene
1. Update the system immediately
Start with a full update. Vulnerabilities in the kernel, OpenSSL, or the web server are the most common way attackers gain access.
# Debian / Ubuntu
sudo apt update && sudo apt upgrade -y
# AlmaLinux / Rocky / RHEL
sudo dnf upgrade -y
Reboot if the kernel was updated.
2. Enable automatic security updates
Manual patching is easy to forget. Enable unattended security updates with unattended-upgrades on Debian and Ubuntu, or dnf-automatic on RHEL-based systems. Limit automatic updates to security fixes if you worry about breaking changes, and monitor the results.
3. Remove unused packages and services
Every installed package is a potential vulnerability. List running services with systemctl list-units –type=service –state=running and listening ports with ss -tulpn. Disable and remove anything you do not need, such as old mail servers, FTP daemons, or sample applications.
4. Use trusted repositories only
Install software only from your distribution’s official repositories or from vendors you trust. Verify GPG signatures, and avoid piping scripts from the internet directly into a shell without reading them first.
Part 2: Users and Authentication
5. Create a non-root administrative user
Day-to-day work should never be done as root. Create a regular user and add it to the sudo (Debian and Ubuntu) or wheel (RHEL-based) group.
sudo adduser adminuser
sudo usermod -aG sudo adminuser
6. Enforce strong password policies
Even with SSH keys, local accounts and applications may still use passwords. Use libpam-pwquality to require minimum length and complexity, and set sensible password aging with chage. Longer passphrases are better than complicated short ones.
7. Lock or remove unused accounts
Audit /etc/passwd and remove accounts that are no longer needed. Lock accounts with usermod -L username, and make sure service accounts use a non-login shell such as /usr/sbin/nologin.
8. Restrict and log sudo usage
Give users only the sudo rights they need. Edit rules with visudo, never directly. Avoid blanket NOPASSWD: ALL entries, and enable sudo logging so you can see who ran which command.
Part 3: SSH Hardening
SSH is the front door to your server, so SSH hardening deserves special attention.
9. Use SSH key authentication
Generate a key pair on your own computer, copy the public key to the server, and test it before you disable passwords.
ssh-keygen -t ed25519 -C “your_email@example.com”
ssh-copy-id adminuser@your_server_ip
Ed25519 keys are modern, fast, and secure. Protect your private key with a passphrase.
10. Disable password logins and root login
Once key login works, edit /etc/ssh/sshd_config:
PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
PermitEmptyPasswords no
Reload SSH with sudo systemctl reload sshd (the service is named ssh on some Debian-based systems), and test from a new session before closing the old one.
11. Tighten other SSH settings
Add further limits to reduce risk:
MaxAuthTries 3
LoginGraceTime 30
AllowUsers adminuser
X11Forwarding no
ClientAliveInterval 300
ClientAliveCountMax 2
AllowUsers restricts who may log in at all, which is one of the most effective settings available. Changing the default port from 22 reduces log noise from bots, but it is not real security by itself. Treat it as optional.
12. Add two-factor authentication
For high-value servers, require a second factor. Tools such as Google Authenticator PAM modules or hardware security keys (FIDO2) add strong protection, even if a private key is stolen.
13. Limit SSH access by network
If you have a fixed office IP or a VPN, allow SSH only from those addresses. This single step removes your server from the sight of most attackers. A VPN such as WireGuard is an excellent way to hide management services entirely.
Part 4: Firewall Configuration and Brute-Force Protection
14. Configure a default-deny firewall
A firewall should block everything by default and allow only what is required. On Ubuntu, UFW makes this simple:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable
On RHEL-based systems, use firewalld. Advanced users can write nftables rules directly. Good firewall configuration also means closing database ports (such as 3306 and 5432) to the public internet.
15. Complete your fail2ban setup
Fail2ban monitors logs and temporarily bans IP addresses that show malicious behavior, such as repeated failed logins. A basic fail2ban setup takes minutes:
sudo apt install fail2ban -y
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit jail.local and enable the SSH jail:
[sshd]
enabled = true
maxretry = 4
findtime = 10m
bantime = 1h
Restart the service and check it with sudo fail2ban-client status sshd. You can also add jails for Nginx, Apache, and WordPress login attempts. Remember to add your own IP to ignoreip so you do not ban yourself.
16. Disable IPv6 only if you do not use it
If you do not use IPv6, either disable it or make sure your firewall rules cover it as well. A common mistake is to secure IPv4 carefully and leave IPv6 completely open.
Part 5: System and Kernel Hardening
17. Apply kernel network hardening with sysctl
Add protective settings to /etc/sysctl.d/99-hardening.conf:
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.icmp_echo_ignore_broadcasts = 1
kernel.randomize_va_space = 2
Apply them with sudo sysctl –system. These settings help against spoofing, redirect attacks, and SYN floods.
18. Secure shared memory and temporary directories
Mount /tmp and /var/tmp with the noexec, nosuid, and nodev options where your applications allow it. This stops many simple attacks that drop and run a malicious file from a temporary folder.
19. Set safe file permissions
Make sure sensitive files are not world-readable. Check /etc/shadow, SSH keys, application configuration files, and database credentials. Set a restrictive default umask such as 027, and search for risky permissions with find / -perm -4000 -type f 2>/dev/null to review SUID binaries.
20. Enable SELinux or AppArmor
Mandatory access control limits what a compromised service can do. RHEL-based systems use SELinux, and Ubuntu uses AppArmor. Keep them in enforcing mode, and learn to read their logs instead of switching them off when something fails.
Part 6: Monitoring, Auditing, and Recovery
21. Centralize and protect your logs
Logs are your evidence after an incident. Make sure rsyslog or journald is working, rotate logs with logrotate, and forward them to a remote server or logging service so an attacker cannot erase them. Review /var/log/auth.log (or /var/log/secure) regularly.
22. Use auditd and file integrity monitoring
The Linux Audit daemon (auditd) records security-relevant events, such as changes to important files and use of privileged commands. Combine it with a file integrity tool such as AIDE, which alerts you when system files change unexpectedly.
23. Scan for malware, rootkits, and misconfigurations
Run periodic scans with ClamAV, rkhunter, or chkrootkit. Then use Lynis, a free auditing tool, to test your configuration:
sudo lynis audit system
Lynis produces a hardening score and a list of suggestions, which makes it a useful way to measure progress.
24. Keep time synchronized
Accurate time is essential for log correlation, certificate validation, and two-factor codes. Use chrony or systemd-timesyncd to stay synchronized with trusted NTP servers.
25. Automate backups and test restores
Hardening reduces risk, but it never removes it. Keep automated, encrypted, off-server backups, and test restoring them regularly. A backup you have never restored is only a hope. Our guide to server backup strategy explains the 3-2-1 rule in detail.
Common Hardening Mistakes to Avoid
- Locking yourself out. Always test SSH and firewall changes in a second session before closing the first one.
- Disabling SELinux or AppArmor instead of reading the logs and fixing the policy.
- Hardening once and never reviewing. Configurations drift as software and users change.
- Forgetting IPv6, cloud security groups, or control panel firewalls, which may override your server rules.
- Skipping documentation. Record every change so that you, or a colleague, can reproduce and audit it later.
- Trusting defaults. Default settings favor convenience, so review every service you expose.
- Ignoring backups. Hardening lowers the chance of a breach, but only tested backups guarantee recovery.
Measuring Progress With Benchmarks
If you want a recognized standard, the CIS Benchmarks provide detailed, consensus-based hardening guidance for most Linux distributions. Tools such as OpenSCAP and Lynis can compare your server with these recommendations and produce a report. Run a scan before you start, again after you finish, and keep both reports. The difference shows what you improved, and the remaining items give you a to-do list for the next maintenance window.
Hardening is also not a one-time job. New software, new users, and new vulnerabilities appear constantly, so review your configuration at least quarterly and after every major change.
Application-Layer Follow-Ups
Your server is only as secure as the services it runs. After the 25 steps above:
- Keep web servers, PHP, databases, and CMS software updated.
- Run each website under its own user account.
- Hide version banners, such as server_tokens off; in Nginx.
- Serve all sites over HTTPS with valid certificates.
- Put a web application firewall in front of public applications.
- Use DDoS protection if your site is a likely target.
Read More – How to Protect Your Server From DDoS Attacks: A Layer-by-Layer Guide
Printable Linux Server Hardening Checklist
| Area | Action | Done |
| Updates | Full update, automatic security updates | ☐ |
| Services | Remove unused packages and services | ☐ |
| Users | Non-root admin user, strong passwords, no unused accounts | ☐ |
| SSH | Keys only, no root login, AllowUsers, MaxAuthTries | ☐ |
| Network | Default-deny firewall, restricted SSH access | ☐ |
| Brute force | Fail2ban enabled and tested | ☐ |
| Kernel | sysctl hardening, secure mount options | ☐ |
| Access control | SELinux or AppArmor enforcing | ☐ |
| Monitoring | Remote logging, auditd, AIDE, Lynis scan | ☐ |
| Recovery | Automated, encrypted, tested backups | ☐ |
Conclusion
Server security is not a single setting. It is a set of habits and layers: updated software, strong authentication, a tight firewall, careful monitoring, and tested backups. This Linux server hardening checklist gives you a clear order of work, from the quick wins (updates, SSH keys, firewall, fail2ban) to deeper controls (kernel settings, SELinux, auditing).
Work through the 25 steps on one server this week, record what you changed, and turn the result into a repeatable script or configuration template. Each server you harden will take less time than the last, and each one will be a much less attractive target.
