Threat Landscape
Within seconds of provisioning a public IP on any cloud hosting provider, automated botnets and malicious scanners begin probing port 22 with dictionary-based username/password combinations. If left with default configurations, weak credentials can lead to server hijacking, cryptojacking, and data leaks.
This production checklist hardens Linux cloud instances against unauthorized intrusion.
1. Enforce Ed25519 SSH Key Pair Authentication
Password authentication should be completely eradicated from public cloud servers. Ed25519 offers state-of-the-art elliptic curve cryptography with smaller key sizes and superior performance compared to legacy 2048-bit RSA.
Generating the Key Pair (on your local machine):
ssh-keygen -t ed25519 -C "admin@edutechz-vps"
Installing the Key on Your Server:
ssh-copy-id -i ~/.ssh/id_ed25519.pub root@YOUR_SERVER_IP
2. Hardening `/etc/ssh/sshd_config`
Edit the OpenSSH server daemon configuration file:
sudo nano /etc/ssh/sshd_config.d/99-hardened.conf
Add the following directives:
# Change default port (mitigates 98% of dumb bot scanners)
Port 2244
# Prohibit empty passwords and disable password-based login completely
PermitEmptyPasswords no
PasswordAuthentication no
KbdInteractiveAuthentication no
# Only permit public key authentication
PubkeyAuthentication yes
# Limit authentication attempts per connection
MaxAuthTries 3
LoginGraceTime 30
# Prohibit direct root login (force named sudoers)
PermitRootLogin prohibit-password
# Modern Cryptographic Ciphers & Algorithms
KexAlgorithms curve25519-sha256,curve25519-sha256@libssh.org,diffie-hellman-group16-sha512
Ciphers chacha20-poly1305@openssh.com,aes256-gcm@openssh.com
MACs hmac-sha2-512-etm@openssh.com
Test the configuration for syntax errors before restarting:
sudo sshd -t && sudo systemctl restart ssh
3. Deploy Fail2Ban with Auto-Banning Jails
Fail2Ban monitors log files (such as `/var/log/auth.log`) for suspicious failed authentication attempts and updates firewall rules to reject offenders.
sudo apt install -y fail2ban
sudo cp /etc/fail2ban/jail.conf /etc/fail2ban/jail.local
Edit `/etc/fail2ban/jail.local`:
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 3
banaction = ufw
[sshd]
enabled = true
port = 2244
logpath = %(sshd_log)s
backend = %(default_backend)s
Restart Fail2Ban:
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
4. Configure UFW (Uncomplicated Firewall) Rate Limiting
UFW includes a built-in stateful rate-limiting module that dynamically rejects IP addresses attempting more than 6 connections within 30 seconds:
# Default policies: deny inbound, allow outbound
sudo ufw default deny incoming
sudo ufw default allow outgoing
# Apply rate limiting to your custom SSH port
sudo ufw limit 2244/tcp comment 'Rate-limited SSH'
# Allow standard web traffic if running websites
sudo ufw allow 80/tcp comment 'HTTP'
sudo ufw allow 443/tcp comment 'HTTPS'
# Enable firewall
sudo ufw enable
Summary Checklist
[x] Password authentication disabled.[x] Ed25519 cryptographic keys installed.[x] Default SSH port shifted from 22.[x] Fail2Ban active with 1-hour ban duration.[x] UFW rate limiting active.