Server Hardening Basics
Practical steps to reduce your VPS attack surface: fail2ban, SSH hardening, and automatic updates.
A fresh VPS gets probed by bots within minutes. GoZen provides platform-level security on all plans, but server hardening is your responsibility on unmanaged servers. This guide covers the practical steps that block most automated attacks.
If you haven’t done initial server setup yet, start there. It covers non-root users, SSH keys, and firewall basics. This article builds on that.
Install Fail2Ban
Fail2Ban monitors log files and bans IPs that show malicious patterns. It’s the single most effective tool against brute-force attacks.
Configure Fail2Ban for SSH
Create a local config file (never edit the main config, it gets overwritten on updates):
sudo nano /etc/fail2ban/jail.local
Add:
[sshd]
enabled = true
port = ssh
filter = sshd
logpath = /var/log/auth.log
maxretry = 5
bantime = 3600
findtime = 600
This bans an IP for 1 hour after 5 failed login attempts within 10 minutes.
sudo systemctl restart fail2ban
Check banned IPs:
sudo fail2ban-client status sshd
Change the SSH Port
Most bots target port 22. Changing the port doesn’t stop a determined attacker, but it eliminates 99% of automated noise from your logs.
sudo nano /etc/ssh/sshd_config
Change:
Port 2222
Before restarting SSH, open the new port in your firewall:
sudo ufw allow 2222/tcp # UFW
sudo ufw deny 22/tcp # Close old port
Then restart: sudo systemctl restart sshd
Keep your current session open and test the new port in a new terminal.
Update your Fail2Ban config to match the new port:
[sshd]
port = 2222
Disable Unused Services
Every running service is a potential entry point. List what’s running:
sudo systemctl list-units --type=service --state=running
Disable anything you don’t need:
# Examples of services you likely don't need
sudo systemctl disable --now cups # Print service
sudo systemctl disable --now avahi-daemon # mDNS
sudo systemctl disable --now postfix # Mail (if not using)
Kernel Security (sysctl)
Harden network behaviour:
sudo nano /etc/sysctl.d/99-hardening.conf
Add:
# Ignore ICMP redirects
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
# Don't send redirects
net.ipv4.conf.all.send_redirects = 0
# Enable SYN flood protection
net.ipv4.tcp_syncookies = 1
# Log suspicious packets
net.ipv4.conf.all.log_martians = 1
# Ignore broadcast pings
net.ipv4.icmp_echo_ignore_broadcasts = 1
Apply:
sudo sysctl -p /etc/sysctl.d/99-hardening.conf
Automatic Security Updates
Quick Security Audit
Run this checklist on any new server:
| Check | Command | Expected |
|---|---|---|
| Root login disabled | grep PermitRootLogin /etc/ssh/sshd_config | no |
| Password auth disabled | grep PasswordAuthentication /etc/ssh/sshd_config | no |
| Fail2Ban running | sudo systemctl status fail2ban | active (running) |
| Firewall active | sudo ufw status or sudo firewall-cmd --state | active / running |
| Auto-updates enabled | Check config files above | Enabled |
| SSH port changed | grep Port /etc/ssh/sshd_config | Not 22 |
What to Do Next
- GoZen Security Scanner - run an external security audit on your server
- Enabling Two-Factor Authentication: add another layer of security
- Monitoring Your Server: watch for suspicious activity
Last updated 05 Apr 2026, 00:00 +0200.