Updated November 2026 · Debian & Ubuntu servers · about 15 minutes
A new server on the internet is probed within minutes. These four steps close the most common doors: key-only SSH, a firewall, automatic banning of repeated login attempts, and automatic security updates. They will not make a server unbreakable, but they remove most of the easy ways in.
Do not lock yourself out. Keep your current SSH session open while you change anything. Test every change from a second window before you close the first.
1. SSH keys only
On your own computer, create a key and copy it to the server (skip the first command if you already have a key):
ssh-keygen -t ed25519
ssh-copy-id youruser@your-server
Log in with the key to confirm it works. Only then switch off passwords and direct root login with a small drop-in file:
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
MaxAuthTries 3
Check the syntax, then reload (the service is called ssh on Debian and Ubuntu):
sudo sshd -t
sudo systemctl reload ssh
2. A simple firewall with UFW
Block everything coming in except what you need. Allow SSH before you enable it.
sudo apt install ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose
Open other ports only as you add services, for example sudo ufw allow 443/tcp for a web server.
3. Ban repeated login attempts with Fail2ban
sudo apt install fail2ban
Put your settings in a local file so updates never overwrite them:
[sshd]
enabled = true
backend = systemd
maxretry = 5
findtime = 10m
bantime = 1h
sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd
Add your own fixed IP address to ignoreip in the same file if you do not want to risk banning yourself.
4. Automatic security updates
sudo apt install unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades
This installs security patches by itself. Servers still need an occasional look: check that updates are applying, and reboot when a kernel update needs it.
What this does not cover
This is a baseline, not a full security review. Backups, monitoring, user and permission design, and anything specific to what the server runs are separate jobs. If the server holds business data, it is worth having someone look at the whole picture.