A Linux VPS exposed to the Internet receives its first SSH login attempts within minutes of going online. Yet most top-ranking guides still date from the Debian 11 and iptables era. Here is a 10-step method updated for Debian 13 "Trixie" and Ubuntu 26.04 LTS, with copy-paste commands and the pitfalls specific to 2026 releases.
Before you start: what changed in 2026
Three recent changes affect how you secure a server, and many tutorials do not mention them yet:
- OpenSSH 10: Debian 13 ships OpenSSH 10.0 and Ubuntu 26.04 ships OpenSSH 10.2. The post-quantum key exchange
mlkem768x25519-sha256is the default, DSA is gone, and sshd already penalises addresses that fail to authenticate (PerSourcePenalties, available since OpenSSH 9.8). - The systemd journal replaces auth.log: on a fresh Debian 13 install, rsyslog is no longer installed and
/var/log/auth.logdoes not exist. An old-style Fail2ban setup simply sees nothing. - nftables everywhere: iptables is now only a compatibility layer. UFW on Ubuntu actually writes nftables rules, and both Fail2ban and CrowdSec can drive nftables directly.
Golden rule for everything below: always keep one SSH session open while you change SSH or the firewall, and test every change from a second session. If something goes wrong, the rescue console (VNC) in your client area is your safety net.
Step 1: update and automate security patches
Start from an up-to-date system, then make sure security fixes install themselves. On Ubuntu 26.04, unattended-upgrades is already active; on Debian 13 you need to install it.
sudo apt update && sudo apt full-upgrade -y
sudo apt install -y unattended-upgrades apt-listchanges needrestart
sudo dpkg-reconfigure -plow unattended-upgrades
systemctl list-timers 'apt-daily*'
Kernel updates only take effect after a reboot. If your service can tolerate a short night-time restart, allow automatic reboots in a local file that package updates will not overwrite:
sudo tee /etc/apt/apt.conf.d/52unattended-upgrades-local > /dev/null <<'EOF'
Unattended-Upgrade::Automatic-Reboot "true";
Unattended-Upgrade::Automatic-Reboot-Time "04:30";
EOF
sudo unattended-upgrade --dry-run --debug | tail -n 20
Otherwise, watch for the /var/run/reboot-required file and schedule reboots yourself.
Step 2: work as a non-root user
The root account should no longer be used to log in. Create an admin user and give it sudo rights. On Ubuntu 26.04, sudo is now provided by sudo-rs, a Rust rewrite: usage is unchanged.
sudo adduser deploy
sudo usermod -aG sudo deploy
su - deploy -c 'sudo -v && echo sudo OK'
Step 3: switch to Ed25519 SSH keys
Passwords are the bots' first target. Generate an Ed25519 key on your own computer, protect it with a passphrase, then copy the public part to the VPS:
# on your computer, not on the VPS
ssh-keygen -t ed25519 -C "laptop-2026"
ssh-copy-id -i ~/.ssh/id_ed25519.pub deploy@VPS_IP
ssh deploy@VPS_IP
If you own a FIDO2 hardware security key, prefer ssh-keygen -t ed25519-sk: the private key then cannot be copied off the token. Only move on once key-based login works.
Step 4: harden sshd with a dedicated drop-in file
Instead of editing /etc/ssh/sshd_config, put your settings in /etc/ssh/sshd_config.d/. Watch out for the trap: for sshd, the first value read wins. On cloud images, a 50-cloud-init.conf file often re-enables PasswordAuthentication yes, so name yours 00-… so that it is read first.
sudo tee /etc/ssh/sshd_config.d/00-hardening.conf > /dev/null <<'EOF'
PermitRootLogin no
PasswordAuthentication no
KbdInteractiveAuthentication no
PubkeyAuthentication yes
AuthenticationMethods publickey
AllowUsers deploy
MaxAuthTries 3
LoginGraceTime 20
X11Forwarding no
AllowAgentForwarding no
ClientAliveInterval 300
ClientAliveCountMax 2
EOF
sudo sshd -t && sudo systemctl reload-or-restart ssh
sudo sshd -T | grep -Ei 'permitrootlogin|passwordauthentication|allowusers|maxauthtries'
sshd -T prints the configuration actually in effect: it is the only reliable way to check that no other file overrides yours. Then, from your computer, check that the post-quantum key exchange is negotiated (you need an OpenSSH 9.9 or newer client):
ssh -v deploy@VPS_IP exit 2>&1 | grep 'kex: algorithm'
# expected: kex: algorithm: mlkem768x25519-sha256
For a full audit of the offered algorithms, the ssh-audit tool is packaged in Debian and Ubuntu (sudo apt install ssh-audit, then ssh-audit localhost).
Should you change port 22?
Changing the port reduces log noise, not risk: with keys and no passwords, port 22 is fine. If you change it anyway on Ubuntu 26.04, note that SSH is socket-activated (ssh.socket) and the listening port is generated from the sshd configuration. In order: first open the new port in the firewall, add the Port directive (for example in 00-hardening.conf), check it with sudo sshd -t, then run sudo systemctl daemon-reload and sudo systemctl restart ssh.socket. Simply restarting ssh.service is not enough. Test a login on the new port from a second session before closing the first one.
Step 5: a default-deny firewall
The principle is the same everywhere: deny all inbound traffic, then open only the services that really need to be public.
On Ubuntu 26.04: UFW
UFW is installed but disabled. Allow SSH before enabling it:
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw limit OpenSSH
sudo ufw allow 80,443/tcp
sudo ufw enable
sudo ufw status verbose
The limit rule temporarily blocks an address that opens more than 6 connections in 30 seconds on the SSH port.
On Debian 13: plain nftables
On Debian, writing the nftables ruleset directly is clearer than adding a wrapper:
sudo apt install -y nftables
sudo tee /etc/nftables.conf > /dev/null <<'EOF'
#!/usr/sbin/nft -f
flush ruleset
table inet filter {
chain input {
type filter hook input priority filter; policy drop;
ct state established,related accept
ct state invalid drop
iif "lo" accept
meta l4proto { icmp, ipv6-icmp } accept
tcp dport 22 accept
tcp dport { 80, 443 } accept
}
chain forward {
type filter hook forward priority filter; policy drop;
}
chain output {
type filter hook output priority filter; policy accept;
}
}
EOF
sudo nft -c -f /etc/nftables.conf && sudo systemctl enable --now nftables
sudo nft list ruleset
Do not block ICMPv6: without it, the server's IPv6 connectivity breaks.
The Docker trap
A port published with docker run -p 8080:80 bypasses UFW's input rules, because Docker inserts its own rules in the forward path. Likewise, the flush ruleset line and the drop policy on forward above are not suitable for a Docker host. On such a server, publish containers on the loopback interface (-p 127.0.0.1:8080:80) and expose them only through your Nginx or Apache reverse proxy.
Step 6: ban attackers with Fail2ban or CrowdSec
Pick one or the other for a given service: two tools banning the same addresses mostly make troubleshooting harder.
Option A: Fail2ban, simple and local
On Debian 13, the configuration must read the systemd journal since auth.log no longer exists. The Debian package already handles this, but it is safer to state it explicitly in your jail.local:
sudo apt install -y fail2ban
sudo tee /etc/fail2ban/jail.local > /dev/null <<'EOF'
[DEFAULT]
bantime = 1h
findtime = 10m
maxretry = 5
banaction = nftables-multiport
banaction_allports = nftables-allports
[sshd]
enabled = true
backend = systemd
[recidive]
enabled = true
backend = auto
logpath = /var/log/fail2ban.log
bantime = 1w
findtime = 1d
EOF
sudo fail2ban-client -t && sudo systemctl restart fail2ban
sudo fail2ban-client status sshd
sudo nft list table inet f2b-table
The recidive jail bans for one week any address already banned several times in a day. To test a filter without waiting for an attack: sudo fail2ban-regex systemd-journal sshd.
Option B: CrowdSec, collaborative
CrowdSec parses your logs like Fail2ban, but also shares malicious addresses detected by its community: your server blocks IPs before they even attack it. The agent detects, and a "bouncer" enforces blocks in nftables. Debian 13 and Ubuntu 26.04 both ship the crowdsec and crowdsec-firewall-bouncer packages in their repositories:
sudo apt install -y crowdsec crowdsec-firewall-bouncer
sudo cscli collections list
sudo cscli bouncers list
sudo cscli metrics
sudo cscli decisions list
Distribution packages often lag behind the vendor's releases. For a newer version, use CrowdSec's official repository instead: there, the bouncer is named crowdsec-firewall-bouncer-nftables. Either way, check that the crowdsecurity/sshd collection is present (it comes with the Linux collection) and that the bouncer runs in nftables mode (the mode: nftables line in /etc/crowdsec/bouncers/crowdsec-firewall-bouncer.yaml). Then add the nginx or apache2 collections for your web server.
Step 7: shrink the attack surface
A service that does not listen cannot be attacked. List what is exposed:
sudo ss -tulpn
systemctl list-unit-files --state=enabled --type=service
For every line listening on 0.0.0.0 or [::], ask yourself whether it really must be reachable from the Internet. A MariaDB, PostgreSQL or Redis database should listen on 127.0.0.1, and you reach it through an SSH tunnel (ssh -L 5432:127.0.0.1:5432 deploy@VPS_IP). Disable what you do not use with sudo systemctl disable --now service-name and remove unneeded packages.
Step 8: harden the kernel with sysctl
A few network and kernel settings turn off legacy behaviour a server does not need. Put them in /etc/sysctl.d/: since Debian 13, /etc/sysctl.conf is no longer honoured (as the Trixie release notes point out), because systemd-sysctl only reads files from the sysctl.d directories. If you upgrade a server from Debian 12, move your old settings into a file under /etc/sysctl.d/.
sudo tee /etc/sysctl.d/90-hardening.conf > /dev/null <<'EOF'
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.conf.all.log_martians = 1
kernel.kptr_restrict = 2
kernel.dmesg_restrict = 1
kernel.unprivileged_bpf_disabled = 1
fs.protected_symlinks = 1
fs.protected_hardlinks = 1
EOF
sudo sysctl --system
These settings leave net.ipv4.ip_forward untouched: Docker, a WireGuard VPN or a router keep working. If your VPS has several interfaces with asymmetric routing, set rp_filter to 2.
Step 9: watch the logs and get alerts
A secure server is a server someone looks at. The systemd journal is enough for routine checks:
journalctl -u ssh --since today
journalctl -u ssh -g 'Accepted' --since '-7 days'
journalctl -p warning -b
To be notified, send alerts (successful SSH login, ban, failed backup) by email or to a chat webhook. For email, use an authenticated SMTP relay on port 587 or 465: on our Linux VPS, as with many providers, outbound port 25 is blocked to prevent spam. If several admins work on the server, auditd also records who changed which sensitive files.
Step 10: back up, then audit
No amount of hardening replaces a backup. Follow the 3-2-1 rule (three copies, two media, one copy off the server) with an encrypted, deduplicating tool such as restic or BorgBackup:
sudo apt install -y restic
export RESTIC_REPOSITORY=sftp:backup@STORAGE_IP:/srv/restic/vps1
restic init
restic backup /etc /home /var/www --exclude-caches
restic forget --keep-daily 7 --keep-weekly 4 --keep-monthly 6 --prune
restic check
A backup you have never restored is only a hypothesis: test a restore at least once a quarter. Finally, measure the result with Lynis, which gives a hardening index and lists what is left:
sudo apt install -y lynis
sudo lynis audit system --quick
Run the audit again after every significant change: the index should go up, and the remaining suggestions should be deliberate choices.
Frequently asked questions
Fail2ban or CrowdSec: which one in 2026?
Fail2ban is enough for a single VPS exposing only SSH and a website: it is lightweight and sends nothing outside. CrowdSec becomes worthwhile once you expose several services or several servers, thanks to its community blocklist and central console.
UFW or nftables?
Both end up in nftables. UFW is simpler for a handful of rules on Ubuntu; an nftables file is clearer and more precise as rules pile up, and it is the natural approach on Debian.
Do you need antivirus on a Linux VPS?
Not for the security of the system itself: updates, SSH keys, a firewall and a small attack surface protect far better. ClamAV still makes sense if the server receives user uploads or email attachments to scan.
How long does it take to secure a VPS?
Allow about an hour for steps 1 to 6 on a fresh server. The rest (attack surface, alerts, tested backups) gets refined over time, as you install new things.
A sound baseline from day one
These 10 steps apply to any Linux VPS, but they are easier on a predictable machine. Our Linux VPS, available in France, Germany and New York from €7 excl. VAT/month (4 GB RAM, 2 vCPU, 45 GB NVMe), run on dedicated vCPUs: Fail2ban, CrowdSec or a Lynis scan never compete with other customers for compute power. Install Debian 13 or Ubuntu 26.04, follow the list in order, and your server will be better protected than the vast majority of those running today.