Infrastructure & SecurityVPS hosting

Your First 30 Minutes on a New VPS: SSH Keys, Firewall, Updates

The essential hardening checklist for a freshly provisioned VPS: key-only SSH, a non-root sudo user, firewall defaults, automatic patching, and fail2ban.

6 min readSayob Engineering
Your First 30 Minutes on a New VPS: SSH Keys, Firewall, Updates

The first thirty minutes after a VPS comes online matter more than the next thirty days. Automated scanners start probing new IP addresses within minutes of them going live, hammering SSH with stolen credential lists and looking for unpatched services. The good news: a short, repeatable hardening routine closes almost every door those bots try. Here is exactly what to do, in order, before you deploy a single line of application code.

Minute 0: Log In and Change the Locks (SSH Keys Only)

Your provider emailed you a root password. Treat it as a one-time token, not a way of life. Passwords can be guessed or leaked; a modern ed25519 key effectively cannot.

On your local machine (not the server), generate a key pair if you do not already have one, and copy it over:

ssh-keygen -t ed25519 -a 100
ssh-copy-id root@your-server-ip

Confirm you can log in with the key, then edit /etc/ssh/sshd_config and lock the door behind you:

DirectiveTypical fresh installHardened value
PasswordAuthenticationyesno
PubkeyAuthenticationyes (implicit)yes (explicit)
KbdInteractiveAuthenticationyesno
PermitRootLoginyesno (after the next section)
MaxAuthTries63

Reload SSH with systemctl reload sshd — and keep your existing session open until you have verified that a fresh key-based login works. Locking yourself out in minute five is a rite of passage nobody needs.

A Non-Root User with Sudo

Working as root day to day means every typo runs with full privileges and every leaked session is a total compromise. Create a normal user and grant it sudo:

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

Test that ssh deploy@your-server-ip works and that sudo -v prompts as expected. Only then set PermitRootLogin no in sshd_config and reload. From this point on, root is reachable only through sudo from an account that authenticates with a key — two locks instead of none.

Firewall Defaults That Block Everything Else

A firewall's job on day one is simple: deny everything inbound, allow everything outbound, and punch exactly the holes you need. With ufw on Ubuntu or Debian:

ufw default deny incoming
ufw default allow outgoing
ufw allow OpenSSH
ufw enable

Add ufw allow 80/tcp and ufw allow 443/tcp only when you actually serve web traffic. Every open port is a promise you have to keep patched — databases, admin panels, and metrics endpoints should listen on localhost or a private interface, never on 0.0.0.0.

A host firewall handles targeted probes; volumetric attacks are a network-layer problem. That is one reason it is worth knowing what your provider filters upstream — Sayob's dedicated servers, for example, sit behind DDoS filtering of up to 400 Gbps, so your ufw rules deal with the trickle, not the flood.

Automatic Security Updates Without Surprise Reboots

An unpatched server drifts toward compromise on its own schedule. On Debian and Ubuntu, unattended-upgrades applies security patches automatically:

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

The nuance is reboots. Kernel and libc updates only take effect after a restart, but you do not want your server bouncing at random. In /etc/apt/apt.conf.d/50unattended-upgrades, choose deliberately:

  • Unattended-Upgrade::Automatic-Reboot "false"; — patches apply, and you reboot on your own schedule (safest for stateful workloads)
  • Unattended-Upgrade::Automatic-Reboot-Time "03:30"; — automatic reboots, but only inside a window you chose

Either policy is fine. What is not fine is never rebooting: check for /var/run/reboot-required weekly and treat a pending kernel update as the security issue it is.

Fail2ban and Basic Intrusion Signals

With key-only SSH, brute-force attempts cannot succeed — but they still fill your logs and waste resources. Fail2ban watches the auth log and temporarily bans IPs that keep failing:

apt install fail2ban

Create /etc/fail2ban/jail.local:

[sshd]
enabled = true
maxretry = 4
findtime = 10m
bantime = 1h

Then run systemctl enable --now fail2ban and verify with fail2ban-client status sshd. While you are there, learn your baseline signals: last shows successful logins, lastb shows failed ones, and journalctl -u ssh tells the full story. Five minutes spent reading logs on a healthy server makes anomalies obvious later.

Snapshots and a Repeatable Checklist

Once the base hardening is done — and before you install anything application-specific — take a snapshot or image if your control panel supports it. A clean, hardened baseline you can roll back to or clone is worth far more than a snapshot of a half-finished app server.

Then make the routine repeatable. Whether it lives in a cloud-init file, a shell script in a git repo, or a plain text checklist, every new server should get:

  1. Key-only SSH, password authentication off
  2. A non-root sudo user; root login disabled
  3. Firewall: default deny inbound, SSH allowed, nothing else yet
  4. Unattended security updates with a deliberate reboot policy
  5. Fail2ban with an sshd jail
  6. A snapshot of the clean state
  7. A dated note of what changed, kept somewhere you will find it

The whole list takes under thirty minutes the first time and under ten once scripted. On a VPS — Sayob's start at EUR 3.47/mo with root access and zero setup fees — that is a small tax for skipping the most common compromise vectors entirely.

FAQ

Should I move SSH to a non-standard port? It quiets log noise but adds no real security — scanners probe all ports. Do it for tidiness if you like, after keys, firewall, and fail2ban are in place, never instead of them.

Is fail2ban pointless once passwords are disabled? No. It throttles pre-auth probing, protects other jails you may add later (mail, web logins), and keeps logs readable. It complements key-only SSH; it does not replace it.

Does this checklist change on bigger machines? The routine is identical on an entry-level VPS and a dedicated EPYC machine. Dedicated hardware adds one extra item: secure the out-of-band access too, since IPMI/KVM is a second door into the server. And wherever you harden, jurisdiction matters — Sayob hosts in the Equinix FR5 data center in Frankfurt under German and EU (GDPR) jurisdiction, so the legal baseline is as solid as the technical one.

TagsVPS

Related articles

Want help planning your hosting setup?

Talk to our team about configurations, locations and the right infrastructure for your workload.