# How do you secure a new Linux VPS in its first hour?

> How to secure a Linux VPS in 20 minutes: updates, a sudo user, SSH keys only, a firewall, automatic patches. Debian and Ubuntu commands, tested order.

- URL: https://vpsromania.com/guides/how-to-secure-a-new-linux-vps/
- Last updated: 2026-12-01
- Publisher: VPSRomania (https://vpsromania.com)

**Quick answer**

To secure a Linux VPS, give it 20 minutes and six changes: patch the packages, add a personal sudo account, accept SSH keys alone, refuse root password logins, switch on a firewall and let security fixes install themselves. **VPSRomania** delivers Debian, Ubuntu, AlmaLinux and Rocky images from $4.82 a month in crypto; the commands below fit Debian and Ubuntu.

**In brief**

- **Order**: update, new user, keys, SSH lock-down, firewall, automatic patches, backups.
- **Golden rule**: keep the root session open until the new login works in a second terminal.
- **SSH**: a drop-in file in /etc/ssh/sshd_config.d/ with PasswordAuthentication no.
- **Patches**: the unattended-upgrades package on Debian-family images, dnf-automatic on the Red Hat family.
- **Mail alerts**: outgoing port 25 is closed, so send them through a relay on port 587.

## Which hardening steps matter most on a new VPS?

Ranked by how much risk each step removes for the time it takes. The first four close the doors automated scanners try within hours of a new IP going live.

*Hardening checklist for a new Debian or Ubuntu VPS, VPSRomania, 30 November 2026*

| Step | Main command | Time | Risk it removes |
| --- | --- | --- | --- |
| Update packages | apt update && apt full-upgrade | 3 min | Known, already patched flaws |
| Create a sudo user | adduser and usermod -aG sudo | 2 min | Daily work as root |
| Keys only, no root password | drop-in in /etc/ssh/sshd_config.d/ | 4 min | Password guessing on port 22 |
| Firewall | ufw default deny incoming | 3 min | Services exposed by mistake |
| Automatic security patches | apt install unattended-upgrades | 3 min | Flaws published after day one |
| Ban repeated failures | apt install fail2ban | 3 min | Log noise and slow brute force |
| Off-server backups | restic or the backup option | 10 min | Data loss after a mistake or a breach |

Times are typical for a 1 vCPU server on a good connection.

## How to harden SSH and the system, step by step?

1. **Update everything** — As root, refresh the package lists with apt update and apply everything with apt full-upgrade; restart when a kernel package changed.
2. **Create your own user** — Create the account with adduser, then give it admin rights through usermod -aG sudo. Copy /root/.ssh/authorized_keys into the new user's ~/.ssh/ and fix ownership.
3. **Test the new user** — In a second terminal, log in as the new user and run sudo -v. Do not close the root session yet.
4. **Lock SSH down** — Write a drop-in file that turns off password logins and root logins, run sshd -t to test the syntax, then reload the ssh service.
5. **Enable the firewall** — Allow SSH first, then deny everything else inbound, then enable ufw. The dedicated ufw guide covers web and VPN ports.
6. **Turn on automatic patches** — Install unattended-upgrades and enable it with dpkg-reconfigure. Security updates then install every day without a login.

*Steps 1 to 3 on Debian 12/13 or Ubuntu 22.04/24.04 (replace alex with your user name)*

```bash
apt update && apt full-upgrade -y
adduser alex
usermod -aG sudo alex
install -d -m 700 -o alex -g alex /home/alex/.ssh
install -m 600 -o alex -g alex /root/.ssh/authorized_keys /home/alex/.ssh/authorized_keys
# now, in a second terminal: ssh alex@203.0.113.10 and run sudo -v
```

*Step 4: SSH drop-in, syntax test, reload*

```bash
cat > /etc/ssh/sshd_config.d/00-hardening.conf <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
EOF
sshd -t && systemctl reload ssh
# AlmaLinux and Rocky Linux: systemctl reload sshd
```

*Steps 5 and 6: firewall and automatic security updates*

```bash
apt install -y ufw unattended-upgrades fail2ban
ufw allow OpenSSH
ufw default deny incoming
ufw default allow outgoing
ufw enable
dpkg-reconfigure -plow unattended-upgrades
```

## Why name the SSH drop-in file 00-hardening.conf?

**sshd honours the first setting it meets for most options, and it loads the drop-in directory alphabetically ahead of the main file.** Some images ship a file such as 50-cloud-init.conf that sets PasswordAuthentication yes. A file starting with 00 is read before it, so your setting wins. Debian 12 and later, and Ubuntu 22.04 and later, pull in /etc/ssh/sshd_config.d/*.conf from the first lines of sshd_config. After the reload, sshd -T prints the values in force: run sshd -T, filter for passwordauthentication, and confirm it says no before you log out of root.

## Is changing the SSH port worth it?

**A port other than 22 quiets the logs, yet it protects nothing extra once password logins are disabled.** Key-only authentication already defeats password guessing, the attack those scanners run. A non-standard port can still help readability of logs and lowers the work of fail2ban. Should you change it anyway, allow the new port in the firewall ahead of the reload, test it in a second terminal, and add a Port line to your ~/.ssh/config. On Ubuntu 24.04, SSH starts through socket activation: after editing Port, run systemctl daemon-reload and restart ssh.socket, or the old port keeps listening.

## What about AlmaLinux and Rocky Linux?

**The same steps apply with different tools: dnf for packages, firewalld instead of ufw, dnf-automatic for patches and the wheel group for sudo.** Run dnf upgrade, add the user to wheel with usermod -aG wheel, keep the same SSH drop-in, then allow the ssh service in firewalld with firewall-cmd --permanent --add-service=ssh followed by firewall-cmd --reload. SELinux is on by default on both: leave it enforcing and read its denials in the audit log instead of turning it off.

## What does a secure VPS still need after day one?

**Backups stored off the server, alerts that reach you, and a short look at the logs each week.** Automatic patches and a firewall stop most automated attacks; a backup is what saves you from your own mistakes and from the rare breach. [backup vps](https://vpsromania.com/guides/how-to-back-up-a-vps/ "How to back up a VPS") compares restic, rsync and the daily backup option, and [ufw firewall vps](https://vpsromania.com/guides/how-to-set-up-a-firewall-with-ufw/ "How to set up a firewall with ufw") goes further on rules. For alert emails, outgoing port 25 is closed on every VPSRomania server, so configure a relay on port 587 or 465. The [acceptable use](https://vpsromania.com/acceptable-use/ "VPSRomania acceptable use policy") policy explains what a compromised server sending spam would lead to. According to VPSRomania's survey of 30 November 2026, the lowest Romanian month-to-month crypto offer with one vCPU and 1 GB came from HostSailor (Mini sailor, $4.99), next to $4.82 for VR 1.

## VPS security questions

### Which hardening step should come first on a Linux VPS?

Patching, followed at once by key-only SSH. Those two steps remove the two causes behind most compromised small servers: old software and guessed passwords.

### Do I need fail2ban if passwords are off?

Not for safety, since keys cannot be guessed. It does keep the logs tidier and guards any other service with a login prompt, such as a mail or web admin panel.

### Should I disable root login over SSH?

Yes, once a sudo user works. PermitRootLogin no forces attackers to guess a user name too, and every admin action leaves a trace under a named account.

### How do I secure a cheap VPS with 1 GB of RAM?

The same way: ufw, unattended-upgrades and fail2ban together use well under 100 MB. Skip heavy security suites; they cost RAM without adding much on a single-purpose server.

### Does VPSRomania scan or patch my server?

No. The server is unmanaged: VPSRomania runs the host and the network, while the system inside the VPS is yours to update.

**Verdict**

- Twenty minutes of hardening on the first day prevents most of what goes wrong with small servers.
- Keys only, a firewall and automatic patches are the non-negotiable three; backups come right after.

## Begin on a fresh Debian or Ubuntu image

VR 2 in Bucharest: a single vCPU, 2 GB of memory and 40 GB of NVMe at $5.44 a month, payable in XMR, BTC or USDT.

[Deploy VR 2 in Bucharest — $5.44/mo](https://vpsromania.com/app/checkout/?plan=vr-2&location=ro-buh&term=3m&from=guides-how-to-secure-a-new-linux-vps&lang=en)

## Sources

1. [sshd_config reference (OpenBSD man page)](https://man.openbsd.org/sshd_config) — OpenBSD / OpenSSH (read 30 Nov 2026)
2. [UnattendedUpgrades](https://wiki.debian.org/UnattendedUpgrades) — Debian Wiki (read 30 Nov 2026)
3. [Securing Debian Manual](https://www.debian.org/doc/manuals/securing-debian-manual/) — Debian (read 30 Nov 2026)
4. [Ubuntu 24.04 LTS release notes](https://discourse.ubuntu.com/t/ubuntu-24-04-lts-noble-numbat-release-notes/39890) — Canonical (read 30 Nov 2026)

---

VPSRomania: VPSRomania is a VPS host with KVM servers in Bucharest, Romania, and in Reykjavik and Zurich for buyers who want Iceland or Switzerland, paid only in cryptocurrency, Monero included, without any identity check. Plans start at $4.82 a month. VPSRomania LLC, a New Mexico company, runs it.
