Skip to content
Back to Blog
Security10 min read

Server Security Hardening Checklist: 12 Configs That Work

Lock down SSH, firewall rules, and running services with this step-by-step checklist. Each config closes a common attack vector on Linux servers.

Written by Abdul AbrorTechnical Hosting Support Engineer
Server Security Hardening Checklist: 12 Configs That Work
On this page

Most compromised servers I've seen in support tickets had SSH running on port 22 with password auth enabled. That's it. Two misconfigurations and the attacker walked right in through brute force.

This checklist walks through twelve specific hardening steps that close the attack vectors I see exploited most often. You'll edit SSH config files, set firewall rules, and disable services that attackers probe first.

1. Move SSH off port 22

Port 22 gets hammered by automated scanners. Moving SSH to a high port above 1024 cuts bot traffic by more than ninety percent in my experience.

Edit /etc/ssh/sshd_config:

Port 2849

Pick any unused port between 1025 and 65535. Restart SSH:

systemctl restart sshd

Before you log out, open a second terminal and verify you can connect on the new port. If SELinux is enforcing, tell it about the new port:

semanage port -a -t ssh_port_t -p tcp 2849

2. Disable root login over SSH

Root should never log in remotely. Create a regular user, add it to sudo, then lock root out.

In /etc/ssh/sshd_config:

PermitRootLogin no

Restart the service. From now on you'll SSH as your regular user and elevate with sudo when needed.

3. Turn off password authentication

Passwords get brute-forced. SSH keys don't.

Copy your public key to the server first:

ssh-copy-id -i ~/.ssh/id_rsa.pub user@yourserver -p 2849

Verify key-based login works, then disable passwords in /etc/ssh/sshd_config:

PasswordAuthentication no
ChallengeResponseAuthentication no
UsePAM no

Restart SSH. Anyone without your private key is locked out now, no matter how many passwords they try.

4. Restrict SSH to specific users

If only two accounts need SSH access, explicitly allow them and deny everyone else.

Add this line to /etc/ssh/sshd_config:

AllowUsers admin deploy

Restart the daemon. Now even if an attacker compromises another account on the system, they can't SSH in.

5. Set up a firewall and default-deny

Most Linux distributions ship with firewalld or ufw. Pick one and enable it. I'll show both.

firewalld:

systemctl enable --now firewalld
firewall-cmd --set-default-zone=drop
firewall-cmd --zone=public --add-service=http --permanent
firewall-cmd --zone=public --add-service=https --permanent
firewall-cmd --zone=public --add-port=2849/tcp --permanent
firewall-cmd --reload

ufw:

ufw default deny incoming
ufw default allow outgoing
ufw allow 2849/tcp
ufw allow 80/tcp
ufw allow 443/tcp
ufw enable

Default-deny means anything you didn't explicitly permit is blocked. That's the posture you want.

6. Disable unused network services

List what's listening:

ss -tuln

You'll see a column of ports. If you spot services you don't recognize or don't need, stop and disable them.

Common culprits:

  • rpcbind (port 111) — needed only for NFS
  • cups (port 631) — print server, rarely needed on a VPS
  • avahi-daemon (port 5353) — local service discovery, usually unnecessary

Disable them:

systemctl stop rpcbind cups avahi-daemon
systemctl disable rpcbind cups avahi-daemon

Every open port is a potential entry point.

7. Install and configure fail2ban

Even with SSH hardened, attackers will probe other services. Fail2ban watches logs and bans IPs after repeated failed attempts.

Install:

yum install fail2ban          # RHEL/CentOS/AlmaLinux
apt install fail2ban          # Debian/Ubuntu

Create /etc/fail2ban/jail.local:

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

[sshd]
enabled = true
port = 2849

Start it:

systemctl enable --now fail2ban

Check banned IPs anytime:

fail2ban-client status sshd

You'll see bans accumulate as bots try to guess passwords that no longer work.

8. Enable automatic security updates

Unpatched CVEs are how attackers get in after the initial hardening. Automate it.

RHEL/CentOS/AlmaLinux:

yum install yum-cron
systemctl enable --now yum-cron

Edit /etc/yum/yum-cron.conf and set:

apply_updates = yes

Debian/Ubuntu:

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

Security patches will install automatically. For critical production boxes you might want manual control, but for most VPS workloads automatic updates save you.

9. Harden kernel parameters with sysctl

A few kernel tweaks make certain network attacks harder.

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

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

# Disable IP forwarding
net.ipv4.ip_forward = 0

# Enable SYN cookies (protect against SYN flood)
net.ipv4.tcp_syncookies = 1

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

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

# Log suspicious packets
net.ipv4.conf.all.log_martians = 1

Apply the changes:

sysctl -p

These won't stop a determined attacker, but they do shut down low-effort scans and some DoS techniques.

10. Remove or secure the web server signature

By default Apache and Nginx advertise their version in HTTP headers. Attackers use that to find known exploits.

Apache — add to /etc/httpd/conf/httpd.conf or your vhost:

ServerTokens Prod
ServerSignature Off

Nginx — add to the http block in /etc/nginx/nginx.conf:

server_tokens off;

Restart the web server. Your headers will now say "nginx" or "Apache" without version numbers.

11. Restrict cron and at to specific users

If an attacker compromises a low-privilege account, you don't want them scheduling jobs.

Create /etc/cron.allow with only the usernames that need cron:

root
admin

Do the same for /etc/at.allow. If these files exist, anyone not listed is denied. No cron.deny or at.deny needed.

12. Audit open ports and services monthly

Hardening isn't one-and-done. Schedule a monthly check.

Run:

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

Compare the output to last month. New listening ports or services? Investigate them. Something you disabled reappeared after an update? Disable it again.

I keep a text file with the expected open ports for each server. Makes the monthly audit a two-minute diff.

What if SSH is still slow to connect?

Sometimes SSH hangs for twenty seconds before the password prompt even after hardening. That's usually DNS.

Add this to /etc/ssh/sshd_config:

UseDNS no

Restart SSH. If your server was trying to reverse-resolve every connecting IP, that line stops it and connections become instant.

How do I test firewall rules without locking myself out?

Open a second SSH session before you reload the firewall. If the new rules break SSH, your existing session stays alive and you can fix it. Or set a cron job that flushes firewall rules in ten minutes — if you get locked out, wait and the rules reset.

Can I automate all twelve steps with a script?

Yes. Ansible, bash scripts, or even a checklist you paste into the terminal line by line. I use Ansible roles for new VPS deployments so hardening happens before any app code touches the box. The first compromise is always the easiest one to prevent.

Do I need all twelve configs or can I skip some?

Steps one through five are non-negotiable for anything internet-facing. The rest depends on your threat model and uptime requirements. A personal blog can skip automatic updates if you'd rather test them. A production app server shouldn't skip anything on this list.

Should I disable IPv6 entirely?

Only if you're certain your apps and monitoring don't use it. Disabling IPv6 can break things in surprising ways. Instead, apply the same firewall rules to IPv6 that you applied to IPv4. Default-deny works the same way.

Check your server today

Pick three items from this list and apply them in the next hour. SSH hardening, firewall rules, and fail2ban cover the most common attack surfaces.

Once those three are live, schedule the rest for this week. Hardening takes less time than recovering from a compromise, and every config here has stopped real attacks on servers I manage.