Skip to content
Back to Blog
Security11 min read

Server Security Hardening Checklist: 11 Steps [2026]

Lock down your Linux server with SSH key enforcement, firewall rules, automatic patching, and monitoring baselines that catch intrusions before they spread.

Written by Abdul AbrorTechnical Hosting Support Engineer
Server Security Hardening Checklist: 11 Steps [2026]
On this page

Your server sits on the internet with root access and every service you've installed. Default configurations ship permissive for ease of setup, not safety. I've seen compromised boxes mining cryptocurrency within hours of deployment because SSH allowed password login and the admin password was "Admin123".

This checklist walks through eleven hardening steps I run on every production Linux box. They're ordered by impact: the first few stop the most common attacks, the later ones catch edge cases and establish long-term resilience.

1. Disable root SSH login and enforce key authentication

Password authentication over SSH is the single biggest attack surface on a new server. Bots scan for open port 22 and try common passwords around the clock.

Generate an SSH key pair on your local machine if you haven't already:

ssh-keygen -t ed25519 -C "[email protected]"

Copy the public key to your server:

ssh-copy-id -i ~/.ssh/id_ed25519.pub user@your_server_ip

Then edit /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no

Restart the SSH daemon:

systemctl restart sshd

Test your key login in a new terminal before you close your existing session. If the key fails, you still have the open session to fix it.

2. Change the default SSH port

Port 22 gets hammered by automated scans. Moving SSH to a high port (above 1024, below 65535) cuts scripted login attempts to near zero.

Pick a port that's not in /etc/services and not used by another service. I usually choose something in the 40000–50000 range. Edit /etc/ssh/sshd_config:

Port 47822

If you're running a firewall (and you should be—see step three), open the new port before restarting sshd:

ufw allow 47822/tcp
systemctl restart sshd

Reconnect on the new port:

ssh -p 47822 user@your_server_ip

Once confirmed, remove the old port 22 rule from your firewall.

3. Configure a firewall and block everything except required ports

Default Ubuntu and Debian installs ship with no firewall enabled. Every service you install opens a port to the world unless you explicitly block it.

I use ufw on Debian-based systems because the syntax is human-readable. Install it if missing:

apt install ufw

Set default policies:

ufw default deny incoming
ufw default allow outgoing

Allow only the services you need. For a web server with custom SSH port:

ufw allow 47822/tcp   # SSH
ufw allow 80/tcp      # HTTP
ufw allow 443/tcp     # HTTPS

Enable the firewall:

ufw enable

Check the rules:

ufw status verbose

On RHEL-based systems, use firewalld instead. The principle is identical: deny by default, permit only known-good traffic.

4. Set up automatic security updates

Manual patching falls behind. Unattended-upgrades on Debian/Ubuntu or dnf-automatic on RHEL-based systems apply security patches without you remembering to SSH in every week.

On Debian/Ubuntu:

apt install unattended-upgrades
dpkg-reconfigure -plow unattended-upgrades

Edit /etc/apt/apt.conf.d/50unattended-upgrades to restrict updates to security repos:

Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
};

On RHEL/CentOS/Rocky:

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

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

Automatic updates handle CVE patches faster than you can. The risk of an update breaking something is lower than the risk of running a month-old kernel with a public exploit.

5. Disable unused services and remove unnecessary packages

Every running daemon is another potential entry point. Default installs often include mail servers, RPC services, and print daemons you'll never use.

List all active services:

systemctl list-units --type=service --state=running

Disable and stop anything you don't recognize or need. Common candidates:

systemctl disable --now avahi-daemon
systemctl disable --now cups
systemctl disable --now rpcbind

Remove packages you're certain you won't use:

apt autoremove --purge postfix exim4

Be cautious here. If you're unsure whether a service is needed, search for its name and purpose before disabling it.

6. Configure fail2ban to block brute-force attempts

Even with key-based SSH, other services (FTP, mail, web panels) might accept passwords. Fail2ban monitors logs and bans IPs after repeated failed logins.

Install fail2ban:

apt install fail2ban

Create /etc/fail2ban/jail.local:

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

[sshd]
enabled = true
port = 47822

Restart fail2ban:

systemctl restart fail2ban

Check active jails and banned IPs:

fail2ban-client status
fail2ban-client status sshd

You can add jails for Apache, Nginx, Dovecot, Postfix, and cPanel if those services run on your box.

7. Harden kernel parameters with sysctl

The Linux kernel ships with network stack defaults that prioritize compatibility over security. A few sysctl tweaks block common spoofing and SYN flood attacks.

Edit /etc/sysctl.conf or create /etc/sysctl.d/99-hardening.conf:

# IP spoofing protection
net.ipv4.conf.all.rp_filter = 1
net.ipv4.conf.default.rp_filter = 1

# Ignore ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0

# Ignore send redirects
net.ipv4.conf.all.send_redirects = 0

# Disable source packet routing
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0

# Log Martians
net.ipv4.conf.all.log_martians = 1

# Ignore ICMP ping requests
net.ipv4.icmp_echo_ignore_all = 1

# SYN flood protection
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2

Apply the changes:

sysctl -p

These settings prevent spoofed packets from routing through your server and make SYN flood attacks harder to execute.

8. Enable and configure a host-based intrusion detection system

Fail2ban catches login attempts. An IDS like AIDE or OSSEC monitors file integrity and catches rootkits, backdoors, and unauthorized binary changes.

AIDE is lightweight and checks file hashes against a baseline. Install it:

apt install aide

Initialize the database (this takes a few minutes):

aideinit

Copy the new database into place:

cp /var/lib/aide/aide.db.new /var/lib/aide/aide.db

Run a manual check:

aide --check

Schedule daily checks via cron:

echo "0 3 * * * root /usr/bin/aide --check | mail -s 'AIDE Report' [email protected]" >> /etc/crontab

When you intentionally update a binary or config, reinitialize the AIDE database to avoid false positives.

9. Set up centralized logging or log forwarding

Local logs disappear if an attacker wipes /var/log or the disk fails. Forward logs to a remote syslog server or a cloud logging service so you have an off-box audit trail.

For rsyslog (default on most distros), edit /etc/rsyslog.conf and add:

*.* @@remote-syslog-server:514

Restart rsyslog:

systemctl restart rsyslog

If you don't have a dedicated syslog server, consider forwarding to a managed service. The cost is low and the visibility is worth it when you need to trace an incident.

10. Restrict user privileges and enforce sudo logging

Don't give users root access unless they need it. Use sudo for specific commands and log every sudo invocation.

Edit /etc/sudoers using visudo:

Defaults logfile="/var/log/sudo.log"
Defaults log_input, log_output

Grant limited sudo privileges:

username ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx

Review the sudo log periodically:

tail -f /var/log/sudo.log

In support tickets I handled, compromised user accounts escalated to root because the user had blanket sudo. Restrict it to the minimum.

11. Establish monitoring baselines for CPU, disk, and network

You need to know what normal looks like before you can spot an intrusion. Set up basic resource monitoring and configure alerts for anomalies.

For simple monitoring, install vnstat for bandwidth tracking:

apt install vnstat
systemctl enable --now vnstat

Check daily bandwidth:

vnstat -d

For CPU and disk, use atop with logging:

apt install atop
systemctl enable --now atop

Atop logs every ten minutes by default. Review historical data:

atop -r /var/log/atop/atop_20260821

For alerting, pair these with a monitoring stack like Prometheus and Grafana, or use a lightweight agent from your hosting provider's control panel.

Sudden spikes in outbound traffic, CPU usage at 100% from an unknown process, or disk writes to unusual paths are all red flags.

How often should you re-audit?

Run through this checklist every time you provision a new server. For existing boxes, re-audit quarterly or after any major software update.

Security drift happens. A developer opens a port for testing and forgets to close it. A deprecated service gets re-enabled after a package update. Quarterly audits catch these before they turn into incidents.

Common questions

Do I need all eleven steps for a small site?
Yes. Attack scripts don't check your traffic volume before trying to brute-force SSH. A small site is just as vulnerable as a large one.

Will automatic updates break my application?
Security updates rarely break userspace apps. Kernel updates need a reboot but are scripted to fall back if the new kernel panics. The bigger risk is running unpatched.

Should I disable IPv6 if I'm not using it?
If you're certain you won't use IPv6, disable it in /etc/sysctl.conf with net.ipv6.conf.all.disable_ipv6 = 1. But most modern networks use IPv6 at least internally, so check first.

How do I test if my firewall is actually blocking ports?
Use an external port scanner like nmap from a different machine or a web-based scanner. Scan your public IP and confirm only your intended ports show as open.

Can I automate this checklist with Ansible or a script?
Absolutely. I keep an Ansible playbook for steps one through seven and run it on every new VPS. File integrity checks and monitoring need per-host tuning, but the firewall and SSH hardening are identical across boxes.

Start with SSH and the firewall

If you do nothing else, enforce SSH keys, move SSH off port 22, and enable a firewall with default-deny. Those three steps block the vast majority of automated attacks you'll see in your logs.

The rest of the checklist builds defense in depth: automatic patching keeps you current, fail2ban stops brute-force, and monitoring catches the anomalies that slip through. None of these steps require expensive tools or deep kernel knowledge, just consistent execution.

Check your current server against this list. If you're missing more than two steps, set aside an afternoon and lock it down.