Knowledge Base

Hardening SSH

Secure SSH on a new Linux server: keys only, no root password login, firewall rules and Fail2ban.

1. Use keys and create a sudo user

adduser deploy
usermod -aG sudo deploy
rsync --archive --chown=deploy:deploy ~/.ssh /home/deploy

Check you can log in as deploy with your key before continuing.

2. Tighten sshd_config

Create /etc/ssh/sshd_config.d/hardening.conf:

PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
MaxAuthTries 3
sudo sshd -t && sudo systemctl restart ssh

3. Firewall

sudo ufw allow OpenSSH
sudo ufw enable

4. Block brute-force attempts

sudo apt install -y fail2ban
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd

5. Keep the system updated

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

Locked yourself out? Use the VNC console to undo the change.

Back to the blog

Leave a Reply

Your email address will not be published. Required fields are marked *

Imagined it.
Now deploy it.

No setup fee on Linux & SSD VPS. Free migration help from our in-house engineers.

Get started
Small business owner smiling at a laptop after launching a website
yourproject.com
Server onlineDeployed in 38 seconds
Deploy a VPS in London