The checklist I run on every new VPS

·5 min read

Every VPS I create gets the same thirty minutes before anything else runs on it. The steps are standard and what took me a while to get right is the order. Two of these steps can lock you out of your own server if you do them in the wrong sequence, and recovering means a rescue console and a restart.

Here is the blueprint. It assumes root SSH access and your public key already in root's authorized_keys.

The whole thing, in order, for when you just want the commands:

sudo apt update && sudo apt upgrade -y
sudo apt install -y curl ufw fail2ban ca-certificates gnupg
sudo adduser deploy && sudo usermod -aG sudo deploy
sudo mkdir -p /home/deploy/.ssh && sudo cp ~/.ssh/authorized_keys /home/deploy/.ssh/
sudo chown -R deploy:deploy /home/deploy/.ssh
sudo chmod 700 /home/deploy/.ssh && sudo chmod 600 /home/deploy/.ssh/authorized_keys
# edit /etc/ssh/sshd_config (step 4), then:
sudo sshd -t && sudo systemctl reload ssh   # test the new login FIRST
sudo ufw default deny incoming && sudo ufw default allow outgoing
sudo ufw allow 22/tcp && sudo ufw enable
sudo systemctl enable --now fail2ban
sudo apt install -y unattended-upgrades && sudo dpkg-reconfigure --priority=low unattended-upgrades
sudo timedatectl set-timezone UTC && sudo systemctl enable --now systemd-timesyncd
sudo apt install -y haveged

1. Update everything first

sudo apt update && sudo apt upgrade -y

Before I harden anything, I want to know I am starting from a patched system. Hardening an outdated box just preserves the vulnerabilities in a nicer container.

2. Install the essentials

sudo apt install -y curl ufw fail2ban ca-certificates gnupg

curl and the certificate tools are obvious. ufw and fail2ban are the two that actually protect the box, and they are easier to configure now than after something is exposed.

3. Create a non-root user and move in with a key

sudo adduser deploy
sudo usermod -aG sudo deploy
sudo mkdir -p /home/deploy/.ssh
sudo cp ~/.ssh/authorized_keys /home/deploy/.ssh/
sudo chown -R deploy:deploy /home/deploy/.ssh
sudo chmod 700 /home/deploy/.ssh && sudo chmod 600 /home/deploy/.ssh/authorized_keys
groups deploy   # should list sudo

Two rules here. adduser asks for a password; set one, because sudo needs it to prompt with once root login is gone in step 4. And root keeps working until step 5 is verified. I never disable anything until the replacement path is proven.

4. Harden sshd

In /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
ChallengeResponseAuthentication no
UsePAM yes
AllowUsers deploy
MaxAuthTries 3
LoginGraceTime 30

(I left out Protocol 2 and X11Forwarding no; both are already the defaults on any modern OpenSSH.)

The line that matters most is AllowUsers. Whatever you do or forget elsewhere, only the named users can log in at all. I also keep UsePAM yes because turning it off quietly breaks things like sudo session handling on some distros, and the hardening guides that say to disable it rarely mention that. The rest closes the obvious doors: no root login, no passwords, few tries, short grace time.

5. Verify before you reload. This is the step people skip.

sudo sshd -t
sudo systemctl reload ssh

sshd -t checks the config without touching the running daemon. If it prints nothing, the config is valid. Only then reload, and then, in a NEW terminal (keep the current session open), confirm you can still log in:

ssh deploy@<ip>

If the new login works, log out of the old root session. If it does not, fix the config from the session you kept open. Reloading before testing, or testing after closing the only working session, is how people end up in the rescue console. This step is why the order matters.

6. Firewall: allow first, enable second

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow 22/tcp        # or your custom port
sudo ufw enable
sudo ufw status verbose   # Status: active

The classic lockout is ufw enable before allowing SSH. Default-deny incoming with SSH allowed is the whole policy; anything else a service needs gets added explicitly, one line at a time, when it is installed.

7. fail2ban

sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd   # Status for the jail: sshd

The default install already jails SSH. The status command should show the jail running with zero bans on a fresh box. From here on, password-guessing bots get four tries against public key auth, then a ban.

8. Enable automatic security updates

sudo apt install -y unattended-upgrades
sudo dpkg-reconfigure --priority=low unattended-upgrades

Answer yes. This covers the security pocket between my manual upgrades, which, being honest, do not happen as often as they should. A guardian that never sleeps still needs the patches to install themselves.

9. Basic OS sanity

sudo timedatectl set-timezone UTC
sudo systemctl enable --now systemd-timesyncd
sudo apt install -y haveged

Logs that agree about time are not optional once you debug anything across services. UTC everywhere, NTP on, and haveged to keep the entropy pool healthy on a virtualized box that has no keyboard or mouse to stir it.

The two traps, again

Reload sshd only after sshd -t passes, and test the new login before closing the old session. Enable ufw only after SSH is allowed. Everything else is recoverable; those two are the ones that cost you a rescue console.

· · ·