Skip to main content
Published on November 30, 2026 Hardening SSH on a Linux VPS takes a few lines of configuration. What holds people back is not security: it is the fear of locking themselves out when sshd reloads. That risk dropped a lot in November. The OnetSolutions console can now change a VPS password in one click and restart it in rescue mode. Together with the KVM console, which goes through neither SSH nor the network, you always have a way back in. This guide hardens SSH in an order that keeps access at every step, on Debian, Ubuntu, AlmaLinux and Rocky Linux: Ed25519 keys only, no more passwords, root by key or not at all, fail2ban, then the console firewall.

What you change, and how to check it

Summary as of November 30, 2026:

Before you start: two sessions and a way back in

Three rules keep you from losing access:
  1. Keep one SSH session open from start to finish. It stays your workbench if the new configuration refuses logins.
  2. Test every change in a second session, never in the one you keep open.
  3. Validate before reloading: sshd -t checks the configuration without applying anything.
The service is called ssh on Debian and Ubuntu, sshd on AlmaLinux and Rocky Linux. The commands below give both.
Find the KVM console on your VPS page in the console now. It opens a local session on the server, independent of SSH and of the firewall.

Install an Ed25519 SSH key

Generate the key on your workstation. Ed25519 is the type our SSH keys documentation recommends:
Copy the public key to the VPS, then test a login that accepts the key only:
On the VPS, list the authorized keys and their type. The type is shown in parentheses at the end of each line:
Good result: every key you need shows (ED25519). An (RSA) or (ECDSA) key will be refused at the next step: replace it with an Ed25519 key first.
A key saved in the console is installed when a VPS is created or reinstalled. For a server already running, ssh-copy-id or a line added to ~/.ssh/authorized_keys does the job.

Create a sudo user so you can do without root

This step is optional if you keep root by key. You need it if you want to forbid root over SSH. On Debian and Ubuntu:
On AlmaLinux and Rocky Linux:
The password is for sudo, not for SSH. Then give the user root’s keys:
In a second session, check the login and the privileges:

Where to put your SSH configuration: a file in sshd_config.d

The OpenSSH manual is explicit: for each keyword, the first value read wins. Included files are read in the lexical order of their names. Debian, Ubuntu, AlmaLinux and Rocky Linux include /etc/ssh/sshd_config.d/*.conf at the top of /etc/ssh/sshd_config. Check it, and look at what the directory already holds:
Good result: the line Include /etc/ssh/sshd_config.d/*.conf appears before any other active directive. You will often find files put there by the system: A file named 10-... is read after 01- but before 25- and 50-. To make yours win over all of them, start its name with 00-. It stays in charge even if cloud-init rewrites its own file on a later boot. Record the effective configuration before you touch anything:

Disable SSH password authentication

Create the hardening file. Pick the PermitRootLogin line that fits you:
KbdInteractiveAuthentication matters as much as PasswordAuthentication. The cloud-init documentation points it out: with PAM, keyboard-interactive authentication can still accept a password. Debian and Ubuntu already turn it off in their sshd_config; declaring it here costs nothing. Validate, then reload:
If sshd -t prints an error, fix the file and run the test again. Do not reload until it is silent.

Check that passwords are really refused

Read the effective configuration again:
Good result:
Depending on the OpenSSH version, prohibit-password shows under its older name, without-password: it is the same setting. Then, from your workstation and in a second session, the three tests that count:
Good result: test 1 opens a session. Tests 2 and 3 stop at Permission denied (publickey). without ever asking for a password. With PermitRootLogin no, add a fourth test: ssh -o PreferredAuthentications=publickey root@203.0.113.10 must be refused too. Close the first session only once everything checks out.

Set up fail2ban on the sshd jail

Without passwords, brute force leads nowhere. fail2ban still earns its place: it bans the bots that cycle through usernames, and trims the log accordingly. What each distribution’s package does, checked on November 30, 2026: Debian 12 no longer installs rsyslog by default: without it there is no /var/log/auth.log, and the default jail does not start. The fix landed in package 1.0.2-3, which Debian 12 did not get. The backend = systemd setting below takes its place.

Debian and Ubuntu

Put your settings in a .local file, read after the package configuration. List in ignoreip the addresses you manage the server from:

AlmaLinux and Rocky Linux

fail2ban comes from the EPEL repository. The fail2ban-systemd package sets it up to read the systemd journal:

Check fail2ban

Good result: fail2ban-client status sshd answers with the Currently failed and Total banned counters and the Banned IP list. fail2ban-regex counts matched lines as soon as bots have tried their luck. To lift a ban:

Restrict SSH to your IP addresses with the console firewall

The console firewall is set up without installing anything on the VPS. Reserved for your addresses, port 22 stops answering bots. First note the address you are connected from:
Then, on your VPS Firewall page in the console: Add one rule per admin address.
From the first rule on, the firewall only accepts the traffic you allow. If the VPS serves a website, add the port 80 and 443 rules right away, as described in the firewall documentation.
Check: your SSH session still opens from your workstation. From another connection, a mobile hotspot for example, ssh gets no answer until it times out.

Locked out: get back in from the console

Each situation has its way out: In rescue mode, the console opens a root session on the rescue system. Mount your system partition, then remove the hardening file or add your key:
Replace /dev/sda1 with the partition lsblk -f points to, and the ssh-ed25519 AAAA... line with your public key. Then leave rescue mode from the Rescue mode tab: the VPS restarts on its own system.

Common pitfalls

A PasswordAuthentication yes read before yours. The first value wins. A 01- file or a setting placed above the Include line takes precedence: only sshd -T tells the truth. Forgetting KbdInteractiveAuthentication. On a system where PAM enables it, passwords are still accepted that way. The keyboard-interactive test reveals it. An RSA key still in use. With PubkeyAcceptedAlgorithms limited to Ed25519, an old RSA key, such as a deployment tool’s, is refused. Take stock with ssh-keygen -lf before reloading. Reloading without sshd -t. One typo in the file and the service refuses new logins. The test takes a second. Banning your own address. A few key failures from a misconfigured workstation are enough. Put your fixed addresses in ignoreip. Updating the firewall after your address changes. If your address changes, add the new rule before removing the old one.

Going further

Have a question about a server hosted with us? Our team is available from your client area.