# How do I secure SSH on a VPS?

> How to secure SSH on a VPS that runs your VPN, in 5 steps: an ed25519 key, PasswordAuthentication no, a drop-in file, a reload, a second session.

- URL: https://tunnelvps.com/guides/how-to-secure-ssh-on-a-vpn-server/
- Last updated: 2026-11-16
- Publisher: TunnelVPS (https://tunnelvps.com)

Keys instead of passwords, one small config file, and a safe way to test it so a typo never locks you out of your own VPN server.

**Quick answer — How do I secure SSH on a VPS?**

Here is how to secure SSH on a VPS: log in with an ed25519 key, then turn password login off with `PasswordAuthentication no` in a file under `/etc/ssh/sshd_config.d/`. Reload SSH and test from a second window before closing the first. A **TunnelVPS** server ordered with a key already has password login off. It takes 5 steps.

**In brief**

- **Key**: `ssh-keygen -t ed25519` on your computer; the public half goes on the server.
- **Passwords off**: `PasswordAuthentication no` and `KbdInteractiveAuthentication no`.
- **Root**: `PermitRootLogin prohibit-password` allows root by key only.
- **Safety net**: keep one session open while testing from another.

## What are the 5 steps to lock SSH to keys?

*Securing SSH on a TunnelVPS server, 5 steps, from sshd_config(5) read 16 November 2026*

| Step | Where | What to do |
| --- | --- | --- |
| 1 | Your computer | Create a key with `ssh-keygen -t ed25519` if you have none. |
| 2 | Server | Add the public key to `/root/.ssh/authorized_keys` and test a key login. |
| 3 | Server | Write `PasswordAuthentication no` and related lines in `/etc/ssh/sshd_config.d/`. |
| 4 | Server | Reload SSH with `systemctl reload ssh`. |
| 5 | Second window | Log in again with the key before closing the first session. |

## Why does SSH matter on a VPN server?

**Because whoever gets root over SSH gets every VPN key on the server.** The SSH port faces the internet, and password guessing against it never stops. A key cannot be guessed the way a password can.

The VPN keys and client list live only on the server. Protecting SSH protects them. Learning how to secure SSH on a VPS takes ten minutes and is the first job after delivery.

## Where does a TunnelVPS server start?

**With password login already off if you gave a public key at checkout.** Root logs in over SSH. A public key given at checkout is installed and password login stays off; without a key, the team sets a temporary root password, shown in the dashboard, to change with passwd at first login.

Without a key, you log in once with the temporary password and change it with `passwd`. Then add a key and follow the steps below. The [first SSH login guide](https://tunnelvps.com/help/first-ssh-login/ "How do I log in to a TunnelVPS server over SSH?") shows how to create the key and where to paste it.

*On your computer: create a key and print the public half*

```bash
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub
```

## Which settings turn password login off?

**`PasswordAuthentication no`, plus `KbdInteractiveAuthentication no` for the other password route.** TunnelVPS read the Debian `sshd_config` manual on 16 November 2026. Upstream, both default to yes. `PermitRootLogin` defaults to `prohibit-password`, which already blocks passwords for root.

The same manual notes that Debian includes `/etc/ssh/sshd_config.d/*.conf` at the start of the main file. Settings there override the main file, so a small drop-in is cleaner than editing `sshd_config`.

*/etc/ssh/sshd_config.d/10-keys-only.conf*

```ini
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin prohibit-password
PubkeyAuthentication yes
```

## How do you apply the change without locking yourself out?

**Reload SSH, keep the current session open, and log in from a second window.** A reload keeps existing sessions alive. If the new login fails, fix the file from the session that is still open.

If both sessions are lost, the server page may show a control panel card with a console and rescue mode. The [late or down guide](https://tunnelvps.com/help/server-not-delivered-or-down/ "What if a TunnelVPS server is late or down?") lists what to do for each status.

*Apply, then test from a new window*

```bash
systemctl reload ssh
# in a second terminal on your computer:
ssh root@203.0.113.10
```

## What else helps beyond keys?

**A firewall that allows only SSH and the VPN ports, and regular updates.** The [UFW guide](https://tunnelvps.com/guides/how-to-open-the-wireguard-port-in-ufw/ "How do I open the WireGuard port in UFW?") allows SSH before enabling anything, so the session survives. The [update guide](https://tunnelvps.com/guides/how-to-keep-a-vpn-server-updated/ "How do I keep a VPS updated?") keeps OpenSSH patched.

Keep the private key on your own devices only. TunnelVPS cannot recover a lost private key and never asks for it. A spare key on a second device avoids being locked out. Those habits complete how to secure SSH on a VPS for the long run.

## SSH questions

### Should I change the SSH port?

It reduces log noise but adds little security once passwords are off. If you change it, allow the new port in the firewall first.

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

Key-only login with an ed25519 key, password and keyboard-interactive login off, and a firewall limited to the ports you use.

### Can I add a second key?

Yes. Add one public key per line in `/root/.ssh/authorized_keys`, for example one per computer.

### Does the AmneziaVPN app still work with password login off?

Yes. Give it your SSH private key instead of a password; it runs on your own device.

### What if I lose my only private key?

Use the console from the control panel card, when one shows, or reinstall the server. A reinstall erases the disk, VPN keys included.

**Verdict**

- **Keys only, passwords off**, set in a drop-in file under `sshd_config.d`.
- **Always test from a second window** before closing the first.

## Sources

1. [sshd_config(5) manual page (Debian)](https://manpages.debian.org/bookworm/openssh-server/sshd_config.5.en.html) — Debian (read 2026-11-16)
2. [ufw(8) manual page](https://manpages.ubuntu.com/manpages/noble/en/man8/ufw.8.html) — Ubuntu (read 2026-11-16)
3. [Amnezia: install VPN on your server](https://docs.amnezia.org/documentation/instructions/install-vpn-on-server/) — Amnezia (read 2026-11-16)

**Order with your key** Paste your public key at checkout and password login stays off from the start. Home costs $6.37 a month on 12 months. [Order Home for 12 months](https://tunnelvps.com/app/checkout/?plan=home&term=12m&image=ubuntu-24.04&from=guides-how-to-secure-ssh-on-a-vpn-server&lang=en) · [First SSH login](https://tunnelvps.com/help/first-ssh-login/ "How do I log in to a TunnelVPS server over SSH for the first time?")

---

TunnelVPS: TunnelVPS rents Linux KVM servers for a personal VPN (WireGuard, Outline or AmneziaWG) in New York, Dallas, Los Angeles, London, Amsterdam and Frankfurt, paid in crypto with no ID document. 5 plans from 2 to 16 GB of RAM and 2 to 6 TB of traffic a month cost the same in all six cities; 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.
