Skip to content

Secure a New Linux VPS in 30 Minutes: 2026 Checklist

Secure a New Linux VPS in 30 Minutes: 2026 Checklist

You just bought a VPS. You have an IP address, a root password or an SSH key, and a project you want online by tonight. Before you install Nginx, Node, PHP or anything else, give the server half an hour of attention first.

Here is why. The moment a server gets a public IP, bots start knocking. They scan whole IP ranges all day, looking for SSH with weak passwords, open databases and forgotten admin panels. They are not after you in particular. They try every server they find, and a fresh, unpatched box with password login turned on is the easiest one to get into.

The good news: the basics take about 30 minutes, and they stop the large majority of these attacks. This guide walks through them step by step on Ubuntu, with notes for Debian where it differs. No security background needed. If you can copy a command and read what it prints, you can do this.

Last checked: November 10, 2026, on Ubuntu 24.04 LTS and 26.04 LTS. Debian 12 and 13 work almost the same way.

The checklist at a glance

# Step Time What it stops
1 Update everything 5 min Known, already-fixed security holes
2 Create your own user with sudo 2 min Working as root all day
3 Log in with an SSH key 5 min Password guessing
4 Turn off password and root login 5 min Brute-force attacks on SSH
5 Turn on the firewall 3 min Services you exposed by accident
6 Install Fail2ban 3 min Bots that keep hammering the door
7 Turn on automatic security updates 3 min Forgetting to patch next month
8 Check what is listening 2 min Databases open to the whole internet

One rule before you start: keep your current SSH session open until the very end. Every time you change how login works, test it from a second terminal window. If something breaks, the open session is your way back in.

1. Update everything first

A fresh image can be weeks or months old. Some of the packages on it may already have public security fixes waiting.

sudo apt update
sudo apt full-upgrade -y

If you are logged in as root, you can leave out sudo for now. When it finishes, check whether the update needs a reboot:

ls /var/run/reboot-required

If that file exists, run sudo reboot, wait a minute and log in again. Kernel updates only take effect after a reboot.

2. Create your own user

Doing everything as root is like driving with no seatbelt. One wrong command (say, rm -rf in the wrong folder) and nothing stops you. Create a normal user and give it sudo, so you have to ask for admin rights on purpose:

adduser deploy
usermod -aG sudo deploy

Swap deploy for any name you like. adduser asks for a password. Pick a strong one, because you will type it every time you use sudo.

Some providers (AWS, for example) already give you a user called ubuntu with sudo. That is fine to keep. Just use it instead of root.

3. Log in with an SSH key, not a password

A password can be guessed. An SSH key in practice cannot. A key comes as a pair: a private key that never leaves your computer, and a public key that you copy to the server.

On your own computer (not the server), create a key if you do not have one yet:

ssh-keygen -t ed25519 -C "your-laptop"

Press Enter to accept the default location. When it asks, set a passphrase. Then if your laptop is ever stolen, the key alone is not enough to get in.

Now copy the public key to the server. On macOS and Linux:

ssh-copy-id [email protected]

On Windows, ssh-copy-id is not included, so use this in PowerShell instead:

type $env:USERPROFILE\.ssh\id_ed25519.pub | ssh [email protected] "mkdir -p ~/.ssh && chmod 700 ~/.ssh && cat >> ~/.ssh/authorized_keys && chmod 600 ~/.ssh/authorized_keys"

Replace 203.0.113.10 with your server's IP. Now open a new terminal and try it:

ssh [email protected]

If you get in without being asked for the server password (your key's passphrase is fine), the key works. Do not move on until it does.

4. Turn off password login and root login

This one step does the most. Once passwords are off, those bots guessing admin123 all day get nowhere.

There is one trap here that catches a lot of people. Many cloud images ship with a file like /etc/ssh/sshd_config.d/50-cloud-init.conf that switches password login back on. SSH uses the first value it finds for each setting. If you only edit the main sshd_config, that file can quietly win.

The clean fix is to make your own file with a name that sorts first:

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

Paste this in:

PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
AllowUsers deploy

AllowUsers means only the users you list can log in over SSH. Use your own username, and if more than one person logs in, list them all separated by spaces.

Before restarting anything, check the config for typos. sshd -t prints nothing if all is well:

sudo sshd -t
sudo systemctl restart ssh

Then ask SSH which settings it is actually using, so you are not just trusting the file:

sudo sshd -T | grep -Ei "permitrootlogin|passwordauthentication|allowusers"

You should see permitrootlogin no and passwordauthentication no. Now the important part: from a second terminal, log in as your user again. It should still work. You can also try ssh [email protected]: it should be refused.

What about changing the SSH port?

Moving SSH from port 22 to, say, 2222 cuts down the noise in your logs, because many lazy bots only try 22. But it does not make the server safer, because anyone who scans your ports will find it. With keys only, port 22 is perfectly fine. If you change it anyway, note that on Ubuntu 24.04 and later, SSH is started through ssh.socket. A port change needs sudo systemctl daemon-reload and sudo systemctl restart ssh.socket, plus a firewall rule for the new port before you restart.

5. Turn on the firewall

A firewall decides which ports anyone can reach. The rule is simple: block everything coming in, then open only what you need. Ubuntu comes with ufw (on Debian, run sudo apt install ufw first).

sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH
sudo ufw allow 80/tcp
sudo ufw allow 443/tcp
sudo ufw enable

Allow SSH before you run ufw enable. If you do it the other way round, you lock yourself out in one keystroke. Check the result:

sudo ufw status verbose

You should see SSH, 80 and 443 allowed, and everything else denied. If the server is not a web server yet, leave out 80 and 443 for now. You can add them later.

If you use Docker, read this. When you publish a port with Docker (-p 5432:5432), Docker writes its own firewall rules, and those skip ufw. The port is open to the world even if ufw says otherwise. For anything only your apps need, like a database or Redis, bind it to localhost:

docker run -p 127.0.0.1:5432:5432 postgres

Many providers (DigitalOcean, Hetzner, AWS, Vultr) also have a firewall in their dashboard. Turning that on as well costs nothing and gives you a second layer.

6. Install Fail2ban

With passwords off, nobody can guess their way into SSH. Bots will still try thousands of times, though, filling your logs and wasting CPU. Fail2ban watches for repeated failed logins and blocks those IPs for a while.

sudo apt install fail2ban -y

Never edit jail.conf directly, because updates overwrite it. Create jail.local instead:

sudo nano /etc/fail2ban/jail.local
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5

[sshd]
enabled = true

Restart it and check that the SSH jail is running:

sudo systemctl restart fail2ban
sudo fail2ban-client status sshd

After a day or so, run that last command again. The "Total banned" number usually tells you exactly why this step is worth it.

On Debian 12 and 13 (and any system without /var/log/auth.log), Fail2ban may refuse to start because it cannot find a log file. Add backend = systemd under [sshd] and restart it.

Don't ban yourself. If you work from a fixed office IP, add ignoreip = 127.0.0.1/8 ::1 YOUR.OFFICE.IP under [DEFAULT].

7. Turn on automatic security updates

You won't remember to log in every week and run updates. Almost nobody does. Ubuntu can install security fixes on its own with unattended-upgrades, which is usually installed already:

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

Choose Yes. By default, it only installs security updates, so it will not jump you to a new version of PHP or Node by surprise.

Some fixes (kernel ones especially) only apply after a reboot. If a short restart at night is okay for your project, open /etc/apt/apt.conf.d/50unattended-upgrades, find these two lines, remove the // in front of them and set:

Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "03:30";

If a reboot at 3:30 AM is not okay (a busy shop, say), leave this off. Instead, put a reminder in your calendar to check /var/run/reboot-required every couple of weeks.

8. Check what is listening

Last step, and the one people skip most. Ask the server which programs are waiting for connections:

sudo ss -tulpn

Look at the "Local Address" column:

  • 127.0.0.1:3306 or [::1]:6379 means only this server can reach it. Good for databases.
  • 0.0.0.0:3306 or *:3306 means it listens on every network interface. Your firewall is now the only thing keeping it private.

MySQL, PostgreSQL and Redis all listen on localhost by default on Ubuntu. Tutorials sometimes tell you to change that to 0.0.0.0 "to make it work". If you need to reach your database from your laptop, use an SSH tunnel instead of opening it to the internet:

ssh -L 3306:127.0.0.1:3306 [email protected]

While that terminal stays open, your database app can connect to 127.0.0.1:3306 on your laptop and reach the server's database safely.

What we don't bother with

Plenty of hardening guides throw 40 steps at you. Some of them matter on a company network. For a single VPS running a website or an API, these give you little for the effort:

  • Port knocking. Clever, but keys already solve the problem it solves, and it makes your own life harder.
  • Disabling IPv6 "for security." It mostly breaks things. Your firewall covers IPv6 too, as long as IPV6=yes is set in /etc/default/ufw (it is by default).
  • Installing a full antivirus suite. On a Linux server you keep patched and locked down, the steps above do far more.

If you lock yourself out

It happens to everyone once. Don't panic, and don't reinstall straight away. Almost every VPS provider has a web console in the dashboard (it may be called "Console", "VNC", "Serial console" or "Recovery"). It connects you to the server as if you had a screen and keyboard plugged in, and it does not go through SSH or the firewall. Log in there with your user's password, fix the file you broke, and restart SSH.

That is also a good reason to take a snapshot in your provider's dashboard once you finish this guide. It costs very little, and if anything goes wrong later, you can roll back to a clean, secured server in a few minutes.

Keep an eye on it

Security is not set-and-forget, but it does not need much time either. Once a month, five minutes:

sudo fail2ban-client status sshd      # who has been banned
last -n 20                            # recent successful logins
sudo journalctl -u ssh --since "7 days ago" | grep -i accepted
df -h                                 # a full disk breaks things quietly

If you see a successful login you don't recognise, treat it as serious: change your keys, look at what changed on the server, and restore from a snapshot if you are unsure.

Scheduling backups or maintenance jobs with cron? Paste the line into our cron expression explainer to see exactly when it will run, and remember the server's clock is usually UTC. Planning a private network for several servers? The subnet calculator works out the ranges.

The basics in this guide protect the server itself. Once your app is running, the software on it needs patching too. Our guide on the PHP2Shell and Node.js Brotli flaws shows what that looks like in practice.

FAQ

Do I really need all this for a small side project? Yes. Bots don't check how important your project is. A forgotten server can be used to send spam or mine crypto, and your provider may suspend your account for it. These steps take 30 minutes once.

Is a strong password enough instead of SSH keys? It is much better than a weak one, but keys are still safer and easier to use day to day. Once your key works, there is no reason to keep password login on.

Does this work on Debian, Rocky Linux or AlmaLinux? On Debian, yes, with the small differences noted above. Rocky and AlmaLinux use dnf instead of apt, firewalld instead of ufw, and the wheel group instead of sudo. The ideas are the same, but the commands are different.

Will automatic updates break my website? Security-only updates rarely break anything, because they patch the version you already have instead of upgrading it. Big version jumps, like a new PHP release, still wait for you to do them by hand.

My hosting is managed. Do I need to do this? On managed or shared hosting, the provider handles most of it for you. This guide is for a VPS or cloud server where you get root access and the server is your responsibility.

Thirty minutes, eight steps, and your server is no longer the easy target bots are looking for. Bookmark this page for the next server you set up. Running through the checklist again takes even less time.