Home / Guides / SSH keys and fail2ban
Guide

SSH keys and fail2ban on a VPS.

SSH is the front door of your server. Keys and rate-limiting stop most automated attacks.

1. Create a key on your own computer

On your computer (not the server)
ssh-keygen -t ed25519 -C "my-vps"
cat ~/.ssh/id_ed25519.pub

2. Install the key on the server

From your computer
ssh-copy-id admin@YOUR-SERVER-IP
ssh admin@YOUR-SERVER-IP

3. Turn off passwords and root login

Test that key login works in a second terminal before you close the first one.

Harden sshd
sudo tee /etc/ssh/sshd_config.d/99-hardening.conf >/dev/null <<'EOF'
PasswordAuthentication no
PermitRootLogin no
KbdInteractiveAuthentication no
EOF
sudo sshd -t && sudo systemctl reload ssh

4. Install fail2ban

Install and enable
sudo apt install -y fail2ban
sudo tee /etc/fail2ban/jail.d/sshd.local >/dev/null <<'EOF'
[sshd]
enabled = true
maxretry = 5
findtime = 10m
bantime = 1h
EOF
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd

5. Check

Continue with the hardening checklist.

Useful commands
sudo journalctl -u ssh -n 20 --no-pager
sudo fail2ban-client status sshd
sudo ufw status
FAQ

Common questions

Should I change the SSH port?

It reduces noise but is not security. Keys and fail2ban matter more.

What if I lock myself out?

Use the in-browser console from your order page to fix the config.

Keep reading

Related pages

VPS hardening checklist: secure a new Linux server in 15 minutes

A practical checklist for a new Linux VPS: SSH keys, a non-root user, firewall, automatic updates and backups, with the commands.

Read more →

Buy a VPS anonymously

Step-by-step: buy a VPS without an ID upload, pay in crypto, keep your access key safe and secure the server on day one.

Read more →

VPS opsec mistakes

The common operational security mistakes that link a server to its owner: reused identities, leaked metadata, logins and DNS. A checklist to avoid them.

Read more →

Order a VPS paid in crypto.

Open the configurator