The Ultimate Guide to Securing Your Linux VPS in 2026
A practical, step-by-step checklist to harden a new Linux VPS: SSH keys, a non-root user, a firewall, automatic updates, Fail2ban, backups and monitoring.

A fresh VPS is reachable from the whole internet within seconds of booting. Automated scanners start knocking on port 22 almost immediately, so the first thirty minutes you spend on a new server matter more than anything you do later.
This guide walks through a Linux VPS hardening checklist that works on any provider. Commands are shown for Ubuntu/Debian and, where they differ, for AlmaLinux/Rocky Linux. Everything here is standard, well-documented tooling
- nothing exotic and nothing that locks you in.
Running a Linux VPS on VPSLab? You get full root SSH access from the first minute, so every step below applies as written.
1. Update everything first
Before you change anything, bring the system up to date so you are not hardening a box with known holes in it.
# Ubuntu / Debian
sudo apt update && sudo apt full-upgrade -y
# AlmaLinux / Rocky Linux
sudo dnf upgrade --refresh -y
If a new kernel was installed, reboot now (sudo reboot) - a kernel update only
takes effect after a restart.
2. Create a non-root user with sudo
Working as root all day means every typo runs with full privileges. Create a
normal account and give it sudo.
adduser alice # Ubuntu/Debian (interactive)
usermod -aG sudo alice
# AlmaLinux / Rocky
useradd -m alice && passwd alice
usermod -aG wheel alice
Log out and back in as the new user, then confirm sudo whoami prints root.
3. Switch SSH to key-based login
Passwords can be guessed; a modern SSH key cannot. On your own computer (not the server), create a key if you don't already have one:
ssh-keygen -t ed25519 -C "alice@laptop"
ssh-copy-id alice@YOUR_SERVER_IP
On Windows, the built-in OpenSSH client supports the same ssh-keygen command;
copy the contents of ~/.ssh/id_ed25519.pub into
/home/alice/.ssh/authorized_keys on the server if ssh-copy-id isn't
available.
Open a second terminal and confirm you can log in with the key before you go any further. Keep that session open while you change the SSH config - it is your safety net if something goes wrong.
4. Harden the SSH daemon
Create a drop-in file so your changes survive package updates:
sudo nano /etc/ssh/sshd_config.d/99-hardening.conf
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
LoginGraceTime 30
X11Forwarding no
AllowUsers alice
Check the syntax, then reload:
sudo sshd -t && sudo systemctl reload ssh # Ubuntu/Debian
sudo sshd -t && sudo systemctl reload sshd # AlmaLinux/Rocky
Should you change the SSH port? Moving SSH off port 22 cuts down log noise
from bots, but it is not real security on its own. If you do it, open the new
port in the firewall before reloading SSH, and on AlmaLinux/Rocky also tell
SELinux about it (sudo semanage port -a -t ssh_port_t -p tcp 2222).
5. Turn on a firewall
Allow only what you actually serve. Start with SSH, then add web ports if you need them.
Ubuntu/Debian (UFW):
sudo apt install ufw -y
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw allow OpenSSH # or: sudo ufw allow 2222/tcp
sudo ufw allow 80,443/tcp # only if you run a web server
sudo ufw enable
sudo ufw status verbose
AlmaLinux/Rocky (firewalld):
sudo systemctl enable --now firewalld
sudo firewall-cmd --permanent --add-service=ssh
sudo firewall-cmd --permanent --add-service=http --add-service=https
sudo firewall-cmd --reload
Network-level DDoS mitigation (included on every VPSLab plan) protects you from volumetric floods; your host firewall decides which legitimate connections reach your services. You want both.
6. Enable automatic security updates
Most compromises exploit vulnerabilities that already had a patch. Let the server install security fixes on its own.
# Ubuntu / Debian
sudo apt install unattended-upgrades -y
sudo dpkg-reconfigure --priority=low unattended-upgrades
# AlmaLinux / Rocky
sudo dnf install dnf-automatic -y
sudo sed -i 's/^apply_updates.*/apply_updates = yes/' /etc/dnf/automatic.conf
sudo systemctl enable --now dnf-automatic.timer
Schedule a monthly maintenance window to reboot for kernel updates, or look at live-patching if the workload can't tolerate restarts.
7. Block brute-force attempts with Fail2ban
Even with passwords disabled, banning abusive IPs keeps logs clean and protects any other services that do accept passwords (mail, web logins).
sudo apt install fail2ban -y # Ubuntu/Debian
sudo dnf install epel-release -y && sudo dnf install fail2ban -y # Alma/Rocky
sudo tee /etc/fail2ban/jail.local >/dev/null <<'EOF'
[sshd]
enabled = true
maxretry = 5
findtime = 10m
bantime = 1h
EOF
sudo systemctl enable --now fail2ban
sudo fail2ban-client status sshd
CrowdSec is a popular alternative that shares blocklists between installations.
8. Remove what you don't use
Every listening service is attack surface. List what is exposed:
sudo ss -tulpn
Disable anything you don't recognise or need:
sudo systemctl disable --now SERVICE_NAME
Databases such as MySQL, PostgreSQL or Redis should almost never listen on a
public interface - bind them to 127.0.0.1 or a private network and connect
through an SSH tunnel when you need remote access.
9. Keep time, logs and alerts in order
- Time sync: accurate clocks matter for TLS, 2FA codes and log forensics.
timedatectlshould show System clock synchronized: yes. - Logs:
journalctl -u ssh --since todayshows today's SSH activity. Consider shipping logs off the server so an attacker can't erase them. - Alerts: a lightweight uptime check (even a free external monitor) tells you when the server stops responding before your users do.
10. Back up - and test the restore
Hardening reduces risk; it doesn't remove it. Keep at least one copy of important data off the server, ideally encrypted and versioned. A Storage VPS in a separate machine works well as a backup target - see our guide to building an off-site backup server with restic, Borg or rclone.
A backup you have never restored is a hope, not a backup. Restore a few files to a temporary directory once a month.
Quick checklist
| Step | Done when… |
|---|---|
| System updated | No pending updates, rebooted after kernel update |
| Non-root sudo user | You log in as that user, not root |
| SSH keys only | PasswordAuthentication no, PermitRootLogin no |
| Firewall on | Only SSH (+ ports you serve) are open |
| Auto security updates | unattended-upgrades / dnf-automatic enabled |
| Brute-force protection | Fail2ban or CrowdSec running |
| Minimal services | ss -tulpn shows only what you expect |
| Off-site backups | Encrypted, scheduled, restore tested |
Frequently asked questions
Is changing the SSH port enough to secure a VPS? No. It reduces noise from automated scanners but anyone can find the new port with a port scan. Key-only authentication and a firewall are what actually protect you.
Do I still need a host firewall if my provider has DDoS protection? Yes. DDoS mitigation absorbs floods of junk traffic; a firewall controls which legitimate connections reach your services. They solve different problems.
How often should I update? Security updates should install automatically every day. Review and apply everything else, and reboot for kernel updates, on a regular schedule - monthly is a sensible minimum.
Ready to put this into practice? Deploy a Linux VPS with full root SSH access - or, for compile-heavy and latency-sensitive workloads, a Ryzen 9 9950X VPS. Both can be paid for with crypto and need only an email to sign up.
Ready to deploy your own VPS?
Privacy-first hosting with crypto payments and instant setup.
Related articles
How to Set Up a Secure, Privacy-First Windows RDP Server on VPSLab
Step-by-step guide to deploying a hardened Windows RDP VPS with full admin access, crypto payments, and zero KYC - perfect for privacy-conscious remote work.
How to Build an Off-Site Backup Server on a Storage VPS (restic, Borg & rclone)
Turn a storage VPS into an encrypted, versioned off-site backup target with restic, BorgBackup or rclone - with schedules, retention and restore tests.
How to Choose a No-KYC VPS Provider: A Practical Checklist
Not every 'no-KYC' host is what it claims. Use this checklist to compare no-KYC VPS providers on signup, payments, terms, logging and reliability.