Skip to content
Back to Blog
Security10 min read

Server Security Hardening Checklist: 9 Steps for 2026

A practical nine-point protocol for hardening Linux servers—covering patches, access controls, firewall rules, and monitoring—that fits into your existing workflow.

Written by Abdul AbrorTechnical Hosting Support Engineer
Server Security Hardening Checklist: 9 Steps for 2026
On this page

Security incidents I've handled as a support engineer share a pattern: attackers hit the easiest targets first. An unpatched SSH service, default credentials, or wide-open firewall rules give them a foothold. The good news? Most breaches are preventable with a structured hardening protocol that takes a few hours to apply and saves weeks of cleanup.

This checklist walks through nine foundational steps I use to lock down Linux servers—CentOS, Ubuntu, AlmaLinux, or any VPS you're running. Each point includes commands you can run today and explains why it matters.

1. Apply OS and package updates immediately

Outdated packages are the first thing automated scanners look for. Set up automatic security updates so you're not relying on memory.

On Ubuntu or Debian systems, install unattended-upgrades:

sudo apt update
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

For RHEL-based distributions (CentOS, AlmaLinux, Rocky Linux), enable dnf-automatic:

sudo dnf install dnf-automatic
sudo systemctl enable --now dnf-automatic.timer

Edit /etc/dnf/automatic.conf and set apply_updates = yes under the [commands] section.

Manual updates work too if you prefer control. Just run apt update && apt upgrade or dnf update weekly. Missing a critical kernel or OpenSSL patch for two months is how breaches start.

2. Harden SSH access

SSH is the front door. Lock it down tight.

First, disable root login. Edit /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes

Restart SSH after changes:

sudo systemctl restart sshd

Before you disable password auth, make sure you've copied your public key to the server:

ssh-copy-id username@your-server-ip

Test the key login in a second terminal before closing your original session. I've seen admins lock themselves out by skipping this step.

Change the default port if you want to reduce noise in your logs. Pick something above 1024 and update the Port directive in sshd_config. Firewall rules need updating too, which we'll cover next.

Add AllowUsers or AllowGroups to restrict which accounts can log in:

AllowUsers deploy admin

This prevents old or forgotten user accounts from becoming entry points.

3. Configure firewall rules

A firewall with a default-deny policy forces you to whitelist only the services you actually run. Most distributions ship with firewalld or ufw.

For ufw on Ubuntu:

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp    # or your custom SSH port
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

For firewalld on CentOS or AlmaLinux:

sudo firewall-cmd --set-default-zone=drop
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload

Check active rules with ufw status or firewall-cmd --list-all. Close database ports (3306, 5432) and admin panels (like cPanel's 2083) unless you access them over VPN or from specific IPs.

If you need to allow a trusted IP for MySQL access:

sudo ufw allow from 203.0.113.50 to any port 3306 proto tcp

Don't leave management interfaces open to the internet.

4. Install and configure Fail2Ban

Fail2Ban watches log files for repeated failed login attempts and bans the offending IPs automatically. It's simple and effective.

Install it:

# Ubuntu/Debian
sudo apt install fail2ban

# CentOS/AlmaLinux
sudo dnf install epel-release
sudo dnf install fail2ban

Create a local config file at /etc/fail2ban/jail.local:

[DEFAULT]
bantime = 3600
findtime = 600
maxretry = 5

[sshd]
enabled = true
port = ssh
logpath = /var/log/auth.log  # or /var/log/secure on RHEL

Restart Fail2Ban:

sudo systemctl enable --now fail2ban

Check banned IPs with sudo fail2ban-client status sshd. In support tickets I've handled, Fail2Ban stops brute-force attacks within minutes of the first attempt.

Add jails for other services like Apache or Postfix if you run them. The default filters cover most common scenarios.

5. Disable unused services and ports

Every running service is a potential attack surface. List what's listening:

sudo ss -tulnp

You'll see open ports and the process names. If you spot something unfamiliar, investigate. A forgotten mail relay or a test database shouldn't be running in production.

Disable services you don't need:

sudo systemctl stop service-name
sudo systemctl disable service-name

Common candidates: cups (printing), avahi-daemon (mDNS), rpcbind (NFS). Web servers don't need them.

Remove unused packages entirely:

sudo apt autoremove

Fewerpackages means fewer updates and fewer CVEs to track.

6. Set up centralized logging

When something goes wrong, logs tell you what happened. But if an attacker compromises the server, local logs might be erased.

Forward logs to a remote syslog server or a managed service. On the server, edit /etc/rsyslog.conf and add:

*.* @192.168.1.100:514

Replace the IP with your log collector. Use @@ for TCP instead of UDP if you want guaranteed delivery.

Restart rsyslog:

sudo systemctl restart rsyslog

For smaller setups, forwarding auth and security logs to a second server you control is enough. Larger environments benefit from tools like Graylog or the ELK stack, but the principle is the same: keep logs somewhere the attacker can't reach.

7. Enable automatic security checks with Lynis

Lynis is an open-source auditing tool that scans your system and reports misconfigurations. It's like a second pair of eyes.

Install it:

# Ubuntu/Debian
sudo apt install lynis

# CentOS/AlmaLinux
sudo dnf install lynis

Run a full audit:

sudo lynis audit system

The report highlights weak file permissions, missing hardening options, and services that should be disabled. You won't fix everything in one pass, but tackle the high-priority warnings first.

Schedule Lynis to run weekly via cron and email the results:

0 3 * * 0 /usr/sbin/lynis audit system --cronjob | mail -s "Lynis Report" [email protected]

Review trends over time. If new warnings appear, something changed.

8. Lock down file permissions and ownership

Wrong permissions let privilege escalation attacks succeed. World-writable files in /tmp or config files owned by the wrong user are red flags.

Check for world-writable files:

sudo find / -xdev -type f -perm -0002 -ls 2>/dev/null

Fix them:

sudo chmod o-w /path/to/file

Sensitive files like private keys and database credentials should be readable only by their service account:

sudo chmod 600 /etc/ssl/private/your-key.pem
sudo chown root:root /etc/ssl/private/your-key.pem

Web files should be owned by the web server user (www-data, apache, nginx), not root. If you see root owning files in /var/www/html, your deployment script needs fixing.

Set the sticky bit on /tmp to prevent users from deleting each other's files:

sudo chmod +t /tmp

This should already be set, but verify it.

9. Monitor intrusion attempts and system integrity

You've hardened the server. Now watch for signs someone got through anyway.

Install aide (Advanced Intrusion Detection Environment) to track file changes:

sudo apt install aide
sudo aideinit
sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db

Run checks daily via cron:

0 4 * * * /usr/bin/aide --check | mail -s "AIDE Report" [email protected]

AIDE alerts you when binaries or config files change unexpectedly. False positives happen after legitimate updates, so correlate alerts with your change log.

For real-time monitoring, set up auditd to log system calls:

sudo apt install auditd
sudo systemctl enable --now auditd

Add rules in /etc/audit/rules.d/audit.rules to watch critical files:

-w /etc/passwd -p wa -k identity
-w /etc/shadow -p wa -k identity
-w /etc/ssh/sshd_config -p wa -k sshd

Reload rules:

sudo augenrules --load

Query logs with ausearch -k identity to see who touched user account files.

Pair this with uptime monitoring. If your server reboots unexpectedly or SSH login counts spike, investigate immediately.

What hardening looks like in practice

Applying all nine steps takes three to four hours on a fresh server. Afterward, you're maintaining patches weekly, reviewing Lynis reports monthly, and responding to Fail2Ban or AIDE alerts as they come in.

The return on that time investment is huge. Automated attacks move on to easier targets when SSH doesn't accept passwords, ports are locked down, and intrusion detection is running. Manual attacks take longer and leave more traces.

Prioritize items one through four if you're short on time—those cover the most common attack vectors I've seen in production environments. Add the rest as you build out your security posture.

How often should I run security updates?

Weekly manual updates or daily automatic security patches both work. The key is consistency. Skipping updates for a month is when you're most vulnerable.

Will Fail2Ban block legitimate users?

It can if someone mistypes their password five times in ten minutes. Set maxretry higher (like 8) or whitelist trusted IPs in /etc/fail2ban/jail.local under ignoreip.

Do I need a firewall if I'm behind a cloud provider's security group?

Yes. Defense in depth means layering controls. If someone compromises another VM in your VPC or your cloud credentials leak, the host firewall is your second line of defense.

Can I harden a server that's already in production?

Absolutely. Apply changes during a maintenance window and test SSH access from a second session before closing your original connection. Rolling updates let you harden live servers without downtime.

Start with SSH and firewall rules

If you're looking at this checklist and feeling overwhelmed, tackle items two and three first: disable root login, enforce key-based SSH, and configure a default-deny firewall. Those two changes alone stop the majority of opportunistic attacks.

Add the rest as time permits. Server security isn't a one-time task—it's a set of habits. Build them in now and your future self will thank you when the next vulnerability drops and your servers aren't exposed.