NEWS

7 min read

New VPS: the security checklist that locks down the server before the bots find it

New VPS: the security checklist that locks down the server before the bots find it
Image: Redação iMasters
News
Reading
7 min
Tables
1
Code
11
In short

A Russian developer documented on Habr the 15-to-20-minute routine he applies to every new VPS before putting any site online. The account shows where most people get it wrong: thinking that hiding a port is the same as closing it.

The background noise every new VPS receives

On November 25, 2026, developer Кирилл Бронников (Lideim) published a direct account on Habr: in the hour before writing the piece, his server received 42 SSH login attempts.

In the last hour, there were 42 attempts to log into my server via SSH. It's not an attack aimed at me personally, but normal background noise: bots constantly scan hosting addresses, trying root with popular passwords.

Кирилл Бронников (Lideim), developer, in an article on HabrЗа последний час на мой сервер пытались зайти по SSH 42 раза. Это не атака на меня лично, а обычный фон: боты круглосуточно перебирают адреса хостингов и пробуют root с популярными паролями.

The central point of the piece, updated by him on November 27, 2026 after community comments, is that hiding the server doesn't work: tools like Shodan and Censys scan the entire internet and find any open port, whether the hosting is new or not. The real defense is to close what can be closed and monitor the rest.

For those who spin up VPSs frequently (a side project, a client, a staging environment), the list works as a copy-paste checklist. It was tested on Ubuntu 22.04 and 24.04, but the concepts apply to any distribution with systemd and apt.

First login: update before anything else

A newly created server usually comes with outdated packages, including already known vulnerabilities. The first access is as root with a password, sent via the provider's panel:

bash
ssh root@1.2.3.4

On first login, SSH shows the server key's fingerprint and asks whether you trust it. This is the classic man-in-the-middle attack moment: ideally, check the fingerprint in the provider's panel or, via VNC console, run ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub and compare it with what the terminal showed before typing yes. After that, just update:

bash
apt update && apt full-upgrade -y

If a screen appears asking about configuration files, the author recommends keeping the local version (keep the local version) and rebooting with reboot when prompted.

A user of your own, never root

The root login is in every password dictionary bots use, and any command mistake under that user compromises the entire system. The next step creates a user with sudo permission:

bash
adduser ivan
usermod -aG sudo ivan

The article is specific about a detail that seems trivial but isn't: avoid names like admin, user, or ubuntu. These are the first ones brute-force scripts try after root.

Swap password for an SSH key

A key isn't something you can guess by trial and error, unlike a password. On the local machine:

bash
ssh-keygen -t ed25519 -C "my-laptop"

The author recommends setting a passphrase for the key: without it, anyone who steals the laptop, a backup, or gets infected with malware inherits direct access to every server that uses that key. To avoid typing the passphrase on every connection, there's ssh-agent.

With the key ready, it goes to the server:

bash
ssh-copy-id ivan@1.2.3.4

On Windows, via PowerShell, the path is three commands (replacing IP and user):

powershell
scp $env:USERPROFILE\.ssh\id_ed25519.pub ivan@1.2.3.4:key.pub
ssh ivan@1.2.3.4 "mkdir -p ~/.ssh && cat key.pub >> ~/.ssh/authorized_keys && rm key.pub"
ssh ivan@1.2.3.4 "chmod 700 ~/.ssh && chmod 600 ~/.ssh/authorized_keys"

Before moving on, it's mandatory to test in a new terminal window, without closing the old one: ssh ivan@1.2.3.4 should log in without asking for the server password, and sudo whoami should answer root. Skipping this check is the mistake that locks people out of their own server.

Turn off password and root login in SSH

With the key validated, the step that actually makes brute force useless is this file:

bash
sudo tee /etc/ssh/sshd_config.d/00-hardening.conf >/dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
X11Forwarding no
EOF
sudo sshd -t && sudo systemctl restart ssh

The author draws attention to a detail that, in his view, is where most people get stuck: many hosting providers already leave a file like 50-cloud-init.conf with PasswordAuthentication yes. SSH reads the files in sshd_config.d/ in alphabetical order and uses the first value it finds for each key: that's why the file is named 00-hardening.conf, since the 00 guarantees it beats 50-cloud-init.conf. Without that prefix, it feels like "passwords are turned off," but password login keeps working.

It's also worth turning off both directives, PasswordAuthentication and KbdInteractiveAuthentication: the second is another way to type a password, and disabling only one leaves the gap open. On Ubuntu 24.04, the sshd -t command may complain about the /run/sshd folder; the author himself lists the fix: sudo mkdir -p /run/sshd.

To confirm the configuration is actually in effect (and not just written in the file), the command is sudo sshd -T, which should answer permitrootlogin no, passwordauthentication no, and kbdinteractiveauthentication no.

Firewall with ufw

The next step closes everything that doesn't need to be open:

bash
sudo apt install -y ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

The limit rule (instead of allow) opens SSH but automatically blocks any IP that opens six or more connections in 30 seconds: an extra layer of brute-force protection built into the firewall itself. Ports 80 and 443 only make sense if the server is going to host a site or web panel; without that, these two lines can be skipped. Order matters: the OpenSSH rule needs to come before enable, otherwise the connection drops in the middle of the process.

A specific warning for those using containers: Docker ignores ufw. A port published as ports: "8080:8080" stays open to the entire internet, regardless of what ufw status shows. For internal services, the right approach is to publish it bound to loopback, like 127.0.0.1:8080:8080.

Fail2ban against the persistent

ufw limit blocks fast bursts; fail2ban deals with those who try slowly, over a longer time:

bash
sudo apt install -y fail2ban python3-systemd nftables
sudo tee /etc/fail2ban/jail.local >/dev/null <<'EOF'
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
backend = systemd
banaction = nftables-multiport
banaction_allports = nftables-allports

[sshd]
enabled = true
EOF
sudo systemctl enable --now fail2ban
sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

The author justifies choosing nftables as the ban mechanism instead of ufw: the banaction = ufw combination is known to fail and, sometimes, corrupt ufw's own configuration. Zero bans on a freshly created server is normal; they show up over time. And if you ban yourself, the rescue command (run from the provider's console) is sudo fail2ban-client set sshd unbanip SEU_IP.

It's worth noting a technical caveat the author himself raises: OpenSSH 9.8 brought an equivalent native protection, PerSourcePenalties, which the server applies on its own against addresses that repeatedly fail authentication. The problem is that Ubuntu 24.04 still ships with OpenSSH 9.6, so this feature isn't available by default, which is why fail2ban remains necessary. The installed version can be checked with ssh -V.

Automatic updates

Last step in the routine: ensuring security patches come in on their own, even if the server goes weeks without human supervision.

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

On the screen that appears, the answer is Yes. Only security updates are applied; the operating system doesn't reboot on its own.

Final checklist

What to checkCommandExpected response
Root closedssh root@1.2.3.4Permission denied (publickey)
Password disabledsudo sshd -Tpasswordauthentication no, kbdinteractiveauthentication no
Firewall activesudo ufw statusStatus: active, OpenSSH LIMIT
Fail2ban runningsudo fail2ban-client statuslist including sshd
No leftover portssudo ss -tlnponly the services you recognize

If the configuration locks you out

The server doesn't break because of this: the provider panel's VNC console works like a physical monitor, without depending on SSH or the firewall. Logged in from there, with the user created in step 2, it's possible to revert whatever got stuck:

bash
# the firewall isn't letting SSH through
sudo ufw allow OpenSSH

# the SSH configuration broke
sudo rm /etc/ssh/sshd_config.d/00-hardening.conf
sudo systemctl restart ssh

After that, just calmly repeat the step where things got stuck.

What remains open

The author himself lists this hardening as a starting point, not a ceiling. Changing the default SSH port reduces the volume of attempts in the logs, but it's not real protection: scanners find non-standard ports within hours.

For those who want to go further, the options mentioned are closing SSH off entirely from the outside (access only via VPN with WireGuard, or port knocking with knockd) and no longer repeating the steps manually, moving all of this into a cloud-init script applied automatically to every new server. An IP whitelist in ufw only makes sense for those with a fixed IP; with mobile or dynamic internet, the risk is locking yourself out.

Translated from the Brazilian Portuguese original · Read the original