Skip to content
ForgeBase is open source.View on GitHub
FutureForge
SecurityInfrastructureLinux8 min read

How do you secure a new VPS? A first-hour checklist

Secure a new VPS in the first hour. Update it, add a sudo user, use SSH keys, disable password login, enable ufw and fail2ban, and set up backups.

By , Co-founder

How do you secure a new VPS? A first-hour checklist

To secure a new VPS, do these things in the first hour: install updates, create a normal user with sudo, log in with SSH keys, turn off password and root login, enable a firewall that only allows what you need, add fail2ban, confirm automatic security updates are on, and set up backups. This guide walks through each step on Ubuntu 24.04 with the exact commands.

Ubuntu 24.04 LTS gets standard security updates until 2029, which makes it a sensible default for a new server.

Why is the first hour so important?

A new server with a public IP address is found by automated scanners very quickly. GreyNoise reports that its new sensors were found by known scanners "within just about an hour". One AWS user saw login attempts on port 22 about 15 minutes after getting a public IP. That is a single anecdote, but it fits the wider picture.

The volume is large too. A SANS honeypot recorded more than 72,000 authentication attempts from over 175 IP addresses in 30 days. Most of this is bots guessing passwords. The steps below make those guesses useless.

Keep one rule in mind throughout: do not close your current SSH session until you have tested a new one. Several steps change how you log in. If something is wrong, the open session is how you fix it.

Step 1: Update the system

Start with the latest packages, so you are not running software with known holes.

sudo apt update
sudo apt upgrade

If the upgrade installs a new kernel, reboot when you are done.

sudo reboot

Step 2: Create a normal user with sudo

Working as root all the time makes every mistake bigger. Create a normal user and give it sudo rights, following Ubuntu's user management guide.

sudo adduser deploy
sudo usermod -aG sudo deploy

Replace deploy with the name you want. The -a flag matters. Without -a, usermod -G removes the user from any group not listed.

Step 3: Log in with SSH keys

SSH keys are much harder to guess than passwords. On your own computer (not the server), create a key if you do not have one, then copy it to the new user.

ssh-keygen -t ed25519
ssh-copy-id deploy@your-server-ip

Now open a new terminal and check that you can log in as the new user, and that sudo works.

ssh deploy@your-server-ip
sudo whoami

The last command should print root. Leave your original session open.

Step 4: Turn off password login and root login

In OpenSSH on Ubuntu 24.04, PasswordAuthentication defaults to yes and PermitRootLogin defaults to prohibit-password. You want both off.

Do not edit the main /etc/ssh/sshd_config file. Files in /etc/ssh/sshd_config.d/ ending in .conf are included at the top of it, and for each setting the first value sshd reads is the one it uses. So a small drop-in file is cleaner and survives package upgrades.

First, check what is already there. Cloud images often include a file from cloud-init, 50-cloud-init.conf, that may set PasswordAuthentication. If it does not exist on your server, skip the second command.

ls /etc/ssh/sshd_config.d/
sudo cat /etc/ssh/sshd_config.d/50-cloud-init.conf

If that file sets PasswordAuthentication yes, change it to no. Because the first value wins, a yes in a file that is read before yours will override your setting.

Then create your own drop-in file:

sudo nano /etc/ssh/sshd_config.d/99-hardening.conf

Add these lines:

PasswordAuthentication no
PermitRootLogin no
PubkeyAuthentication yes

Check the configuration for errors, confirm the values sshd will actually use, and restart it.

sudo sshd -t
sudo sshd -T | grep -E 'passwordauthentication|permitrootlogin|pubkeyauthentication'
sudo systemctl restart ssh

The second command should show passwordauthentication no and permitrootlogin no. If it does not, another file is setting the value first.

Before you close anything, open another new terminal and log in as your user again. If it works, you are safe to close the old session. If it fails, fix it from the session you kept open.

Step 5: Enable the firewall (ufw)

On Ubuntu, ufw is installed but disabled by default. The order of commands matters. Allow SSH first, or enabling the firewall will cut off your own connection.

sudo ufw allow OpenSSH
sudo ufw enable
sudo ufw status verbose

The status output should show Default: deny (incoming), allow (outgoing), with OpenSSH allowed.

If the server will host a website, allow web traffic too:

sudo ufw allow 80/tcp
sudo ufw allow 443/tcp

Only open ports for services you are actually running.

Step 6: Install fail2ban

fail2ban reads log files such as /var/log/auth.log and bans IP addresses that fail to log in too many times. With password login already off, it mainly cuts down noise and load, but it is still worth having.

sudo apt install fail2ban

Do not edit jail.conf, because upgrades can overwrite it. Put your settings in jail.local instead.

sudo nano /etc/fail2ban/jail.local

A minimal configuration for SSH:

[sshd]
enabled = true
bantime = 10m
findtime = 10m
maxretry = 5

These match the defaults in fail2ban's own jail.conf: five failures within ten minutes earns a ten-minute ban. Writing them out makes them easy to change later. Then start it and check the jail:

sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd

Step 7: Confirm automatic security updates are on

On Ubuntu, unattended-upgrades is installed by default and applies security updates daily. Do not assume it, though. Check.

systemctl status unattended-upgrades
cat /etc/apt/apt.conf.d/20auto-upgrades

The settings live in two files in /etc/apt/apt.conf.d/: 20auto-upgrades turns the daily runs on, and 50unattended-upgrades controls what gets installed. If the package is missing, install it with sudo apt install unattended-upgrades.

Step 8: Set up backups and snapshots

Security includes being able to recover. Most providers offer backups and snapshots, and they are not the same thing. On Hetzner Cloud, for example:

BackupsSnapshots
How they runAutomatically, dailyManually, when you take one
How many are keptUp to 7Kept until you delete them
Includes attached volumesNoNo

Source: Hetzner backups and snapshots documentation.

That last row catches people out. If your database or uploads live on an attached volume, neither backups nor snapshots include it. You need a separate backup of that data.

Two more habits:

  • Take a snapshot before risky changes, like a major upgrade.
  • Test a restore. A backup you have never restored is a guess. Restore to a new server once, and check that the data and the app actually come back.

Step 9: Close ports you are not using

Finally, see what is listening on the server.

sudo ss -tulpn

Each line is a service accepting connections. For anything you do not recognise or do not need, stop and disable the service, or make sure ufw is not allowing that port. Databases and admin panels should usually listen only on 127.0.0.1 and be reached through an SSH tunnel, not opened to the internet.

The first-hour checklist

  1. Update packages and reboot if needed.
  2. Create a sudo user with adduser and usermod -aG sudo.
  3. Set up SSH keys and test login as the new user.
  4. Check 50-cloud-init.conf, then disable password and root login in a drop-in file. Test a new session before closing the old one.
  5. Allow OpenSSH in ufw, then enable it.
  6. Install fail2ban and configure it in jail.local.
  7. Confirm unattended-upgrades is active.
  8. Turn on backups, back up volumes separately, and test a restore.
  9. Review listening ports and close what you do not need.

Frequently asked questions

Should I change the SSH port from 22?

It can reduce log noise from bots, but it is not real protection on its own. Key-only login with password authentication turned off does the real work. If you do change the port, update your ufw rule before you restart SSH.

Do I still need fail2ban if password login is disabled?

It is less critical, because bots cannot guess a key. It still bans repeat offenders, which keeps logs cleaner and reduces load. It is also useful later, when you add other services that do accept passwords.

What happens if I lock myself out?

Many providers offer a web-based console in their dashboard that works even when SSH does not. You can log in there and fix the SSH or firewall settings. This is the main reason to keep your old session open while you test changes.

Are automatic updates safe on a production server?

By default, unattended-upgrades on Ubuntu applies security updates, not every available upgrade, which keeps the changes small. Some updates still need a reboot to take effect, so plan a regular time to restart and check the server.

Is this enough to call my server secure?

It is a solid baseline for a fresh server, not the end. You still need to keep applications updated, watch logs, protect secrets, and repeat a restore test now and then. The next layer is monitoring, so you find out about problems before your customers do.

Next steps

These nine steps fit in the first hour and close the most common doors. After that, security is an ongoing habit, not a one-time setup. If you are still deciding what kind of server to run, read VPS vs shared hosting vs cloud, and for the bigger picture on deploys and monitoring, see does a small team need DevOps?.

If you would rather have this done and maintained for you, our DevOps service sets up hardened servers with tested backups.

About the author

Nahal

Co-founder, FutureForge Studios

Self-taught sysadmin working across mechatronics, embedded systems and IoT. Builds projects involving autonomous drones, smart antenna positioning, code and hardware.

More from Nahal
Related serviceDevOpsDeploys, servers, monitoring

Working on something like this?

Send us the problem. A person reads it and replies within one working day.