Linux Security

Harden SSH server on Linux

Lock down SSH without locking yourself out — test every change in a second session.

16 min read Intermediate Updated 9 Jun 2026

Step-by-step guide

Work through each section in order. Stop when your issue is resolved — you do not need every step for every situation.

Warning

Use a sudo-capable account, keep shell history for audit, and back up critical paths before changing boot, SSH, or package state.

What you will achieve

Lock down SSH without locking yourself out — test every change in a second session.

1) Configure secure sshd defaults

sudo nano /etc/ssh/sshd_config

2) Recommended directives

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
MaxAuthTries 3
AllowUsers youradmin

3) Test before closing active session

sudo sshd -t
sudo systemctl restart ssh
sudo systemctl status ssh

Related guides

hardening linux ssh