Free tools / sshd_config generator

SSH hardening config generator

Build a hardened OpenSSH server config for Ubuntu, Debian or any distribution with OpenSSH 8.5 or newer. Pick the options, copy the file, then test it with sshd -t before you reload. The output works as a drop-in file or as a full /etc/ssh/sshd_config.

Everything runs in your browser. Nothing you type is sent to a server or stored.

File

Login

Limits and timeouts

Forwarding and crypto

  • Password login will be off. Make sure your public key is in ~/.ssh/authorized_keys for every user listed above.
/etc/ssh/sshd_config.d/00-hardening.conf
# /etc/ssh/sshd_config.d/00-hardening.conf
# Generated at nocthost.com/tools/sshd-config-generator
# sshd uses the first value it reads for each keyword, and files in
# sshd_config.d are read in name order, so 00- wins over 50-cloud-init.conf.

Port 22

# Authentication
PermitRootLogin no
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitEmptyPasswords no
MaxAuthTries 3
LoginGraceTime 30

# Sessions
ClientAliveInterval 300
ClientAliveCountMax 2
X11Forwarding no
AllowAgentForwarding no

# Modern key exchange, ciphers and MACs (OpenSSH 8.5 or newer)
KexAlgorithms [email protected],curve25519-sha256,[email protected],diffie-hellman-group18-sha512,diffie-hellman-group16-sha512
Ciphers [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
MACs [email protected],[email protected],[email protected]
Keep your current SSH session open until you have logged in again from a second terminal. A typo in sshd_config can lock you out.
Test and reload
sudo nano /etc/ssh/sshd_config.d/00-hardening.conf   # paste the config, save
sudo sshd -t   # no output means the syntax is valid
sudo sshd -T | grep -Ei 'port|passwordauth|permitroot|allowusers'   # effective values
sudo systemctl reload ssh   # the unit is called sshd on RHEL, Rocky and Alma
# From a NEW terminal, before closing the current one:
ssh -p 22 user@your-server-ip

How to use

  1. Add your SSH public key to ~/.ssh/authorized_keys for every user you plan to allow, and confirm that key login works.
  2. Choose the options below. The drop-in file is the safer choice on Ubuntu 22.04 and newer and on Debian 12, because it does not touch the stock config.
  3. Copy the config to the path shown above the output box.
  4. Run sudo sshd -t. No output means the syntax is valid. Then check the values sshd will really use with sudo sshd -T.
  5. Reload SSH, and keep your current session open. Open a second terminal and log in again before you close the first one.

Frequently asked questions

Why is the drop-in file called 00-hardening.conf and not 99-hardening.conf?

sshd uses the first value it reads for each keyword, and it reads files in /etc/ssh/sshd_config.d in name order. Many cloud images ship 50-cloud-init.conf with PasswordAuthentication yes, which would win over a file named 99-hardening.conf. A name that sorts first makes your settings take effect.

Will changing the SSH port stop attacks?

It cuts the noise in your logs from bots that only scan port 22, but it is not a security control. Key-only login and a disabled root login are what actually protect the server. If you change the port, open it in your firewall before you reload sshd.

What if I lock myself out?

Keep the current session open until a new login works. If you are already locked out, use the web console or rescue mode from your server provider, fix or delete the file, and reload sshd.

Do the modern ciphers break older clients?

Any OpenSSH client from the last several years, current PuTTY releases and current libraries connect fine. Very old clients and some embedded devices may fail. If one does, turn the modern algorithms option off.

Further reading

More free tools

Need a server to try it on? Deploy an Ubuntu VPS