A new VPS is reachable from the whole internet the moment it boots. You get a public IP, a root login and an SSH port that bots start knocking on long before your first app is installed.
The good news: securing a VPS isn't a weekend project. Ten steps, done in the right order, close the doors most attacks walk through. The order matters more than people think, because two of these steps can lock you out of your own server if you do them too early.
This guide walks through the first 10 steps after setting up a Linux VPS: updates, a sudo user, SSH keys, SSH hardening, two firewall layers, the Docker port trap, Fail2ban, automatic security updates, closing unused services and backups. If you're still choosing a server, start with what a VPS is and when you need one.
The commands assume Ubuntu, and every setting comes from Ubuntu's server docs, Docker's docs and Hostinger's support pages. Some links here are affiliate links. They don't change your price.

Why does a new VPS need securing right away?
A fresh server is built to be easy to reach, not hard to break into. Root can usually log in with a password, every listening service is exposed, and nothing watches for repeated failed logins.
That's fine for the first five minutes. It's not fine for a server that will hold your n8n credentials, a database or client sites.
Here's the order I follow, and why it's this order:
- Steps 1 to 4 make sure you can log in safely with a key before you take password and root access away.
- Steps 5 to 7 limit what the internet can reach and slow down anyone guessing.
- Steps 8 to 10 keep the server patched, lean and recoverable.

Step 1: How do you update a new VPS?
Log in as root with the details from your provider's dashboard, then install every pending update:
If the update touched the kernel, Ubuntu leaves a file at /var/run/reboot-required. Reboot so the new kernel is actually running:
Provider images are often weeks or months old, so this first update can be large. Do it before you install anything else.
Step 2: How do you create a non-root sudo user?
Root can do anything, and every bot on the internet already knows its username. Create your own user and give it sudo rights instead:
Pick a strong password when adduser asks. You'll still need it for sudo, even after password logins over SSH are turned off.
Open a second terminal and check the new account works before you go any further:
If the last command prints root, your user has admin rights through sudo.
Step 3: How do you set up SSH key login?
An SSH key replaces a guessable password with a key file that never leaves your computer. Ubuntu's docs recommend the ed25519 algorithm for its shorter keys and lower processing cost.
Run these on your own computer, not on the server:
Set a passphrase when ssh-keygen asks. If the key file is ever copied off your laptop, the passphrase is what stops it working.
ssh-copy-id adds your public key to ~/.ssh/authorized_keys on the server. Ubuntu's docs add one check: only your user should be able to write to that file.
Now log out and SSH in again. If it doesn't ask for your account password (it may ask for the key passphrase), key login is working.

Step 4: How do you disable root login and password authentication?
This is the step that locks people out, so keep your current SSH session open the whole time.
Ubuntu reads extra SSH settings from files in /etc/ssh/sshd_config.d/, and its docs point out that OpenSSH uses the first value it finds for most settings. Some provider images already put a file in that folder. Naming yours with a 00 prefix means it's read first, so your values win.
Add these lines:
Then test the configuration before you restart anything. Ubuntu's docs recommend sshd -t for exactly this, because a broken config can stop SSH from starting:
The last command prints the settings SSH is really using. You want to see permitrootlogin no and passwordauthentication no.
Now open a new terminal and log in again with your key. Only close the old session once the new one works.
Ubuntu also supports two-factor authentication for SSH with hardware keys or one-time codes. It's worth adding for a server several people log in to.
Step 5: How do you set up a firewall on a VPS?
A firewall decides which ports the internet can reach. On a VPS you can have two layers, and I'd use both.
Turn on UFW on the server
UFW is Ubuntu's default firewall tool, and Ubuntu's docs note it starts disabled. Allow SSH first, then web traffic, then switch it on:
Allowing OpenSSH before ufw enable is the part that matters. Do it in the other order and the firewall cuts your own connection.
If you only ever log in from a fixed IP, you can go further and allow SSH from that address alone, as Ubuntu's docs show with sudo ufw allow proto tcp from YOUR_IP to any port 22.
Add the provider's firewall in front
A provider firewall filters traffic before it ever reaches your server. On Hostinger it's under Security, then Firewall, in the VPS dashboard. Hostinger's support page says a firewall group drops all traffic by default, so you add an Accept rule for each port you need, starting with SSH. Rule changes apply in two minutes or less, and connections that are already open aren't cut.
Keep the two layers in sync. A port has to be open in both before anything can reach it.
Step 6: Why does Docker bypass UFW, and how do you fix it?
This one surprises almost everyone who self-hosts apps. Docker's own docs say Docker and UFW are incompatible: when you publish a container port, the traffic is routed before it reaches the rules UFW uses. So a port you never opened in UFW can still be wide open to the internet.

There are two practical fixes:
- Publish container ports on 127.0.0.1 only, and put a reverse proxy like Caddy or Nginx in front to serve them over HTTPS on 443.
- Rely on the provider firewall, which sits outside the server, so Docker can't change it.
In a compose file, the first fix looks like this:
My guide to self-hosting n8n with Docker on a VPS uses exactly this pattern behind Caddy, and the wider self-hosting apps on a VPS guide applies it to other tools.
Step 7: How do you install Fail2ban to block brute-force attempts?
Fail2ban reads log files, spots IP addresses with too many failed logins and blocks them in the firewall for a set time. Install it and turn on the SSH jail:
Put your settings in jail.local rather than editing jail.conf, so package updates don't overwrite them. On systems that log only to the systemd journal and have no /var/log/auth.log, add backend = systemd to the sshd section.
Keep expectations honest. Fail2ban's own README says it can reduce the rate of incorrect login attempts but "cannot eliminate the risk presented by weak authentication." With password logins already off from Step 4, it mostly cuts log noise and slows scanners down.
Step 8: How do you turn on automatic security updates?
Ubuntu installs security updates on its own through the unattended-upgrades package. Its docs say the package is installed by default and runs once a day. Confirm it's on:
You want both lines in 20auto-upgrades set to "1". The dry run shows which updates it would apply without changing anything.
One gap: by default it won't reboot for kernel updates. Automatic-Reboot is false out of the box. If a nightly reboot is acceptable for your apps, set it in /etc/apt/apt.conf.d/50unattended-upgrades:
The time uses the server's own time zone, so check it with timedatectl first. If you'd rather reboot by hand, look for /var/run/reboot-required once a week.
Step 9: How do you find and close services you don't need?
Every listening service is a door. List them:
Go through each line. Anything listening on 0.0.0.0 or [::] is reachable from outside, unless a firewall blocks it. For each one, either you need it, it should listen on 127.0.0.1 only, or it should be removed:
Databases are the classic mistake. MySQL, Postgres or Redis rarely need to be public. Bind them to localhost and let your apps connect locally.
While you're here, Ubuntu's docs show a small extra: adding DebianBanner no to your SSH hardening file stops SSH from announcing your OS version to anyone who connects.
Step 10: How do you back up a VPS before something goes wrong?
Security includes recovery. If a bad update, a mistake or an attacker breaks the server, backups decide whether you lose an hour or a month.
Check what your provider gives you. Hostinger's support page, as of 11 November 2026, lists:
| Feature | How it works on Hostinger VPS |
|---|---|
| Weekly backups | On by default, stored separately from the server, two kept |
| Daily backups | Paid upgrade, two daily copies kept on top of the weekly ones |
| Snapshot | Made by hand, only one at a time, expires after one day |
| Restore | Overwrites the whole VPS and can't be cancelled once started |

Use a snapshot right before risky work, like a major upgrade, and rely on scheduled backups for everything else. Hostinger also notes that VPS backups aren't encrypted at rest, so keep a separate copy of databases and important files somewhere you control, such as object storage. The same thinking is behind my WordPress security checklist, where backups are part of security, not an afterthought.
A backup you've never restored is a guess. Restore one to a test server at least once.
Which VPS makes these steps easier?
Every step above works on any Linux VPS. A few provider features make it smoother: a cloud firewall outside the server, automatic backups, snapshots and a browser console for when SSH goes wrong.
I recommend Hostinger's KVM VPS for self-hosting because it includes all four in the dashboard covered above. My Hostinger review goes through the plans, and if you're hosting n8n specifically, my roundup of n8n hosting providers compares other options.
Frequently asked questions
If you only have ten minutes today, do Steps 3 and 4: key login on, passwords and root login off. That one change shuts out most automated attacks. Then add the firewalls, check your Docker ports and confirm backups are running before you put anything important on the server.


