# How do I secure a Linux VPS?

> How to secure a Linux VPS in 8 steps: SSH keys, a sudo user, root login off, a firewall, Fail2ban, automatic updates and off-server backups.

- URL: https://saltvps.com/guides/how-to-secure-a-linux-vps/
- Last updated: 2026-11-16
- Publisher: SaltVPS (https://saltvps.com)

**Quick answer — How do I secure a Linux VPS?**

To secure a Linux VPS, log in with an SSH key, create a sudo user, turn off root and password login, allow only needed ports in a firewall, add Fail2ban, enable automatic security updates and keep backups elsewhere. A **SaltVPS** server can start key-only from checkout, which covers step 1 of these 8.

**In brief**

- **First hour**: keys, a sudo user, root login off, firewall on.
- **First day**: Fail2ban and automatic security updates.
- **First week**: a tested backup stored on another machine.
- **Order matters**: always allow SSH in the firewall before you enable it.
- **Same steps** on Debian and Ubuntu; AlmaLinux and Rocky Linux differ in package names.

## How do you secure a Linux VPS step by step?

**Work in this order and keep one SSH session open until each change is tested from a second one.**

1. **Use an SSH key** — Paste a public key at checkout, or add one to /root/.ssh/authorized_keys and test it before going further.
2. **Update the system** — Run apt update && apt upgrade on Debian and Ubuntu, or dnf upgrade on AlmaLinux and Rocky Linux. Reboot if a new kernel was installed.
3. **Create a sudo user** — Add a normal user with admin rights and copy your key to it, so daily work no longer runs as root.
4. **Lock down SSH** — In /etc/ssh/sshd_config, set PermitRootLogin no and PasswordAuthentication no, check with sshd -t, then restart the SSH service.
5. **Turn on a firewall** — Deny incoming traffic by default and allow SSH plus the ports your apps use. ufw does this on Debian and Ubuntu, firewalld on AlmaLinux and Rocky.
6. **Install Fail2ban** — Fail2ban reads the SSH log and bans addresses that fail to log in too many times.
7. **Enable automatic security updates** — unattended-upgrades on Debian and Ubuntu, dnf-automatic on AlmaLinux and Rocky, so patches land without a login.
8. **Back up off the server** — Send encrypted copies of data and configs to another machine, then test a restore.

## Which tool handles each security step on each system?

**Debian and Ubuntu share one set of tools; AlmaLinux and Rocky Linux share another.**

*Security tools by step on Debian or Ubuntu and on AlmaLinux or Rocky Linux*

| Step | Debian / Ubuntu | AlmaLinux / Rocky Linux | Detailed guide |
| --- | --- | --- | --- |
| Admin user | adduser, group sudo | useradd, group wheel | Sudo user guide |
| Firewall | ufw | firewalld (firewall-cmd) | Firewall guide |
| Login bans | fail2ban from apt | fail2ban from EPEL | Fail2ban guide |
| Security patches | unattended-upgrades | dnf-automatic | Automatic updates guide |
| Backups | restic or rsync | restic or rsync | Backup guide |
| SSH service name | ssh | sshd | First SSH login page |

## Why do SSH keys matter more than anything else?

**Bots try passwords on port 22 of every public IPv4 address, all day.** A key-only login makes those guesses useless, because no password is accepted at all. The rest of this list only reduces noise and limits damage.

On SaltVPS, a public key pasted at checkout is installed for root and password login stays off. Without a key, the team sets a temporary root password; change it with `passwd`, then follow the [first SSH login page](https://saltvps.com/help/first-ssh-login/ "How do I log in to a SaltVPS server over SSH?") to move to a key.

## What should you do in the first hour on a new VPS?

**Create the admin user, close root login and turn on the firewall, in that order.** Each has its own guide:

- [Create a sudo user](https://saltvps.com/guides/how-to-create-a-sudo-user-on-a-vps/ "How do I create a sudo user on a VPS?") and copy your key to it.
- [Set up a firewall](https://saltvps.com/guides/how-to-set-up-a-ufw-firewall-on-a-vps/ "How do I set up a firewall on a VPS?") that allows SSH before it blocks the rest.
- [Install Fail2ban](https://saltvps.com/guides/how-to-install-fail2ban-on-a-vps/ "How do I install Fail2ban on a VPS?") to ban repeat offenders.

Then test a fresh login as the new user from a second terminal. Only close the root session when that works.

## What does a VPS host already handle, and what is left to you?

**On an unmanaged KVM server, the host runs the hardware and network; the operating system is yours.** SaltVPS checked its plan list on 16 November 2026: none of the 7 plans includes backups, and outbound port 25 is closed on every server. So patches, firewall rules and copies of your data are your job.

KVM gives each server its own kernel, so a neighbour cannot change your system. The [KVM explainer](https://saltvps.com/what-is-a-kvm-vps/ "What is a KVM VPS?") covers what that isolation means. Reboot, reinstall and delete are sent from the dashboard and carried out by a person; a reinstall erases the disk, which is one more reason to keep backups elsewhere.

## Linux VPS security: questions

### Should I change the SSH port?

It cuts log noise but adds little real protection. Keys and Fail2ban do the actual work. If you change it, allow the new port in the firewall first.

### Is Ubuntu or Debian more secure on a VPS?

Both get regular security updates. What matters more is applying them, using keys and keeping few services open.

### What is the best way to secure a Linux VPS in 2026?

Key-only SSH, no root login, a default-deny firewall, Fail2ban, automatic security updates and tested off-server backups. Nothing on that list costs money.

### Do I need antivirus on a Linux VPS?

Usually not for a server you run yourself. Updates, few open ports and least-privilege users matter more.

### How do I see who logged in?

Run last for recent logins, and journalctl -u ssh (or -u sshd) for SSH attempts.

**Verdict**

- **Securing a Linux VPS starts with SSH keys**; the firewall, Fail2ban and updates come next.
- **Backups are the last line**: no SaltVPS plan includes them, so store copies on another machine.

## Sources

1. [Ubuntu Server documentation: security](https://documentation.ubuntu.com/server/) — Canonical (2026-11-16)
2. [Securing Debian Manual](https://www.debian.org/doc/manuals/securing-debian-manual/) — Debian (2026-11-16)
3. [sshd_config(5) manual page](https://man.openbsd.org/sshd_config) — OpenBSD project (2026-11-16)

**Start from a key-only server** Paste your SSH public key at checkout and root logs in with it only, password login off. [Order Flake for 12 months](https://saltvps.com/app/checkout/?plan=flake&term=12m&from=guides-how-to-secure-a-linux-vps&lang=en) · [All guides](https://saltvps.com/guides/ "Which VPS guides and Linux tutorials does SaltVPS publish?")

---

SaltVPS: SaltVPS sells Linux KVM VPS in New York, Dallas, Los Angeles, London, Amsterdam and Frankfurt, paid in crypto with no ID document. Seven plans from 2 to 32 GB of RAM cost the same in all six cities, and on the 12-month term each is priced at least 25% under a named comparable plan of a no-KYC crypto host, read on 16 November 2026. The operator is DomaineGoat LLC, Panama.
