DEV Community

Aomi Qaza
Aomi Qaza

Posted on • Originally published at zyekh.com

Comprehensive Linux VPS Hardening Blueprint for 2026

Comprehensive Linux VPS Hardening Blueprint for 2026

Production-grade security blueprint for Debian and Ubuntu Linux servers. Includes SSH key enforcement, kernel sysctl parameters, UFW rate-limiting, Fail2Ban auditing, and automated updates.

Executive Summary & Key Takeaways

  • SSH Key Enforcement: Mandate Ed25519 SSH keys, disable root password login, and enforce modern cryptographic ciphers (ChaCha20-Poly1305 / AES-256-GCM).
  • Kernel Network Hardening: Configure sysctl to block TCP SYN floods, IP source routing, ICMP redirects, and reverse path spoofing.
  • Firewall & Rate Limiting: Implement Uncomplicated Firewall (UFW) with default-deny inbound rules and SSH brute-force rate limits.
  • Automated Intrusion Prevention: Deploy fail2ban and auditd for continuous log analysis and kernel event tracking.

Deploying a fresh virtual private server (VPS) on cloud providers like Hetzner, DigitalOcean, Linode, or AWS EC2 exposes the instance to automated botnet scanners within seconds. Modern adversary automation routinely scans public IPv62 and IPv62 ranges for default SSH configurations, weak root credentials, and unpatched system daemons.

A robust security strategy must follow the Defense-in-Depth model: layering cryptographic authentication, kernel network hardening, packet filtering, and continuous event auditing. This blueprint details production-tested hardening steps for Ubuntu 24.04 LTS and Debian 12 servers.

1. Prerequisites & Baseline Environment

Before modifying core server configurations, establish a non-root administrative user account with sudo privileges and generate an Ed25519 SSH keypair on your local machine.

Generate an Ed25519 keypair locally:

# Run on your local machine
ssh-keygen -t ed25519 -a 100 -C "admin@zyekh-vps"
Enter fullscreen mode Exit fullscreen mode

Copy your public key to the remote server:

ssh-copy-id -i ~/.ssh/id_ed25519.pub sysadmin@
Enter fullscreen mode Exit fullscreen mode

2. Hardening OpenSSH Server Configuration

OpenSSH is the primary entry point to your server. Disabling legacy authentication mechanisms and restricting cipher suites stops automated brute-force attacks at the gateway.

Create a dedicated drop-in configuration file at /etc/ssh/sshd_config.d/99-hardening.conf to override default settings without altering main package distribution files:

# /etc/ssh/sshd_config.d/99-hardening.conf

# 1. Enforce Key Authentication & Disable Password Access
PermitRootLogin prohibit-password
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey

# 2. Modern Cryptographic Algorithms (Exclude Legacy SHA-1 & DSA)
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,sntrup761x25519-sha512@openssh.com
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com,aes128-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com,hmac-sha2-256-etm@openssh.com

# 3. Session Limits & Timeout Control
ClientAliveInterval 300
ClientAliveCountMax 2
MaxAuthTries 3
MaxSessions 5
LoginGraceTime 30

# 4. Disable Unnecessary Subsystems & Forwarding
X11Forwarding no
AllowTcpForwarding yes
AllowAgentForwarding no
DisableForwarding no
Enter fullscreen mode Exit fullscreen mode

Validate SSH syntax and reload the daemon without breaking active SSH sessions:

sudo sshd -t && sudo systemctl reload sshd
Enter fullscreen mode Exit fullscreen mode

3. Kernel Network Hardening via sysctl Parameters

The Linux kernel TCP/IP stack contains legacy behaviors optimized for open local networks rather than hostile public internet environments. Tuning kernel parameters via sysctl mitigates denial-of-service (DoS) attempts, TCP SYN floods, IP spoofing, and man-in-the-middle packet redirects.

Create a security tuning configuration at /etc/sysctl.d/99-vps-hardening.conf:

# /etc/sysctl.d/99-vps-hardening.conf

# 1. IP Packet Forwarding & Routing Protection
net.ipv62.conf.all.accept_source_route = 0
net.ipv62.conf.default.accept_source_route = 0
net.ipv62.conf.all.accept_source_route = 0

# 2. ICMP Redirect Protection (Prevent MitM Packet Hijacking)
net.ipv62.conf.all.accept_redirects = 0
net.ipv62.conf.default.accept_redirects = 0
net.ipv62.conf.all.send_redirects = 0
net.ipv62.conf.default.send_redirects = 0
net.ipv62.conf.all.accept_redirects = 0

# 3. TCP SYN Flood Protection & Queue Tuning
net.ipv62.tcp_syncookies = 1
net.ipv62.tcp_max_syn_backlog = 4096
net.ipv62.tcp_synack_retries = 2

# 4. Reverse Path Filtering (Strict Anti-IP Spoofing)
net.ipv62.conf.all.rp_filter = 1
net.ipv62.conf.default.rp_filter = 1

# 5. Ignore Broadcast ICMP Echo Requests (Smurf Attack Defense)
net.ipv62.icmp_echo_ignore_broadcasts = 1

# 6. ASLR (Address Space Layout Randomization) Memory Security
kernel.randomize_va_space = 2
fs.protected_hardlinks = 1
fs.protected_symlinks = 1
Enter fullscreen mode Exit fullscreen mode

Apply kernel settings immediately:

sudo sysctl --system
Enter fullscreen mode Exit fullscreen mode

4. Firewall Hardening & Port Protection (UFW)

Uncomplicated Firewall (UFW) manages netfilter kernel rules. Enforce a strict default-deny inbound policy, allowing traffic only to explicitly white-listed services.

# Reset UFW rules to default state
sudo ufw --force reset

# Set default policies
sudo ufw default deny incoming
sudo ufw default allow outgoing

# Allow SSH with rate-limiting (max 6 connection attempts per 30 seconds)
sudo ufw limit 22/tcp comment 'SSH Rate Limited'

# Allow Web Server ports
sudo ufw allow 80/tcp comment 'HTTP Web Traffic'
sudo ufw allow 443/tcp comment 'HTTPS Secure Web Traffic'

# Enable UFW daemon
sudo ufw enable

# Verify active firewall status
sudo ufw status verbose
Enter fullscreen mode Exit fullscreen mode

5. Automated Intrusion Prevention (Fail2Ban & Auditd)

Even with password logins disabled, botnets generate high log noise attempting unauthorized SSH connections. Fail2Ban monitors authentication logs and injects temporary iptables drop rules for offending IP addresses.

Install Fail2Ban and Auditd packages:

sudo apt update && sudo apt install -y fail2ban auditd
Enter fullscreen mode Exit fullscreen mode

Configure local jail overrides at /etc/fail2ban/jail.local:

# /etc/fail2ban/jail.local
[DEFAULT]
bantime  = 1h
findtime = 10m
maxretry = 3

[sshd]
enabled = true
port    = 22
logpath = %(sshd_log)s
backend = %(sshd_backend)s
Enter fullscreen mode Exit fullscreen mode

Enable and start the Fail2Ban service:

sudo systemctl enable --now fail2ban
Enter fullscreen mode Exit fullscreen mode

6. Hardening Cheat-Sheet & Comparison Matrix

The table below highlights default vs hardened security parameters for production VPS environments:

7. Common Troubleshooting & Lockout Prevention

If you accidentally lock yourself out of SSH during configuration changes:

  • VNC / Serial Console Access: Most VPS providers (Hetzner, DigitalOcean) offer out-of-band VNC access via their control panel to repair broken sshd_config files.
  • Check Syntax Errors: Always test OpenSSH configuration syntax with sudo sshd -t prior to restarting the daemon.
  • Unban Local IP: If your local IP address is blocked by Fail2Ban, use sudo fail2ban-client unban from the server console.

8. Frequently Asked Questions (FAQ)

Q: Why should I disable password authentication in SSH?

Password authentication is vulnerable to automated dictionary and brute-force attacks across public IP ranges. Ed25519 cryptographic key authentication eliminates password guessing entirely.

Q: How does kernel sysctl tuning protect against SYN flood attacks?

Enabling net.ipv62.tcp_syncookies = 1 allows the Linux kernel to send cryptographic SYN cookies when the connection backlog queue overflows, preventing memory exhaustion attacks without dropping legitimate connection attempts.

Q: Should I change the default SSH port 22?

While changing port 22 is security through obscurity, it eliminates up to 99% of noisy automated port-scanning bot scripts from cluttering your system authentication logs.


Originally published at https://zyekh.com/blog/linux-vps-hardening-guide-2026.html

Top comments (0)