TABI CLOUD
VPS

How to secure a VPS: UFW, fail2ban and key-only SSH

6 min read · Updated October 2026 · By Tabi Cloud

Bots scan every public IP address looking for weak logins within minutes of a server going online. A few simple steps stop most of them. Commands here target Ubuntu and Debian and may vary on other distributions. DDoS protection is included on Tabi Cloud plans, but server-level hardening is still your job.

1. Set up a firewall with UFW

Allow SSH first, or you will lock yourself out.

  1. sudo apt install ufw -y
  2. sudo ufw allow OpenSSH
  3. sudo ufw allow 80/tcp
  4. sudo ufw allow 443/tcp
  5. sudo ufw enable
  6. sudo ufw status verbose

Only open ports for services you really run. If you change the SSH port, allow that port before enabling.

2. Install fail2ban

It bans IPs that repeatedly fail to log in.

  1. sudo apt install fail2ban -y
  2. sudo systemctl enable --now fail2ban
  3. sudo fail2ban-client status sshd

To customise, copy /etc/fail2ban/jail.conf to /etc/fail2ban/jail.local and edit there so updates do not overwrite your changes.

3. Disable password login

Only do this after your SSH key works. Keep a second session open while you test.

  1. sudo nano /etc/ssh/sshd_config
  2. Set PasswordAuthentication no
  3. Set PermitRootLogin no, or prohibit-password if you still need root with keys
  4. sudo sshd -t to check for errors
  5. sudo systemctl restart ssh

On some systems the service is called sshd, so use that name if ssh fails. Test a new login in another terminal before closing the old one.

4. Keep things updated

5. Other good habits

Quick check

Run sudo ss -tulpn to list listening ports. If you see something you do not recognise, find out what it is.

Questions? Open a ticket on our Discord or email support.

Want your own server? Join our Discord and tell us the game. We set it up and send you the details. Need help with an error from this guide? Open a ticket there.

GET STARTED ON DISCORD

More guides

VPSWhat is a VPS and how is it different from shared hosting?VPSHow to choose a VPS plan: vCPU, RAM and diskVPSFirst steps on a new Linux VPS: SSH, updates, user and keys