Skip to content
Dorian FINKEL
SSHSecurityLinuxTutorial · 2026 · 3 min read · Updated 9 October 2026
Level · BeginnerDuration · 15 min

Harden a server’s SSH access

Keys instead of passwords, no root login, a list of allowed users: a few settings that shut the door on dictionary attacks. And the read-order trap that silently cancels them.

Prerequisites

  • Working SSH access
  • A second session kept open during changes, so you don’t lock yourself out

01Switch to keys

Generate a key on your workstation, protected by a passphrase, then copy its public part to the server. Check that key login works before disabling passwords.

Example · Shell (workstation)
ssh-keygen -t ed25519
ssh-copy-id dorian@server

02The settings

Rather than editing sshd_config, a file in sshd_config.d (included at the top of the main file on Debian and Ubuntu) keeps your changes separate.

By default, PasswordAuthentication is yes, PermitRootLogin is prohibit-password and MaxAuthTries is 6.

Example · /etc/ssh/sshd_config.d/00-hardening.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
AllowUsers dorian
MaxAuthTries 3

03The trap: the first value wins

sshd keeps the first value it reads for each option, not the last. Files in sshd_config.d are read in alphabetical order, and cloud images often drop a 50-cloud-init.conf containing PasswordAuthentication yes.

A file named hardening.conf would be read after it (digits sort before letters) and its setting ignored. Hence the 00- prefix: it comes first. sshd -T shows the configuration actually applied.

Example · Shell
sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|maxauthtries'

04Test, then reload

sshd -t validates the syntax without applying anything. Then reload the service (ssh on Debian and Ubuntu, sshd elsewhere) and test from a new session, keeping the old one open.

Example · Shell
sshd -t && systemctl reload ssh

Key takeaways

  • An ed25519 key, tested before turning passwords off.
  • No root, a list of allowed users.
  • First value read = value applied: prefix the file with 00-.
  • sshd -T to check, sshd -t before every reload.

Official sources