Browse guides

Secure SSH access

Require key authentication and block direct root login without locking yourself out.

Intermediate10 min readUpdated July 18, 2026
1

Back up the configuration

Before changing SSH, make a copy of its configuration so that you can restore it if needed.

sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.backup
2

Apply safe rules

Create a dedicated override file at /etc/ssh/sshd_config.d/99-hardening.conf.

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
LoginGraceTime 30

SSH key required

Only disable passwords after validating key access in a second session.

3

Validate and reload SSH

Test the syntax before reloading the service. No output means that the configuration is valid.

sudo sshd -t
sudo systemctl reload ssh

Test without closing your session

Open a new terminal and reconnect with your sudo user before leaving the current session.