BlogLinux & scripting

SSH hardening: keys, ciphers, and CA-signed certificates

Disable passwords, pick modern ciphers, and issue SSH certificates so you stop managing authorized_keys by hand.

Aug 5, 2025·4 min readIntermediate·By the SecOpsLog team · command-tested

SSH is still the front door to most Linux fleets — and the first service attackers probe on port 22. A hardened sshd disables password authentication, restricts algorithms to modern sets, limits who can log in, and optionally trusts a SSH certificate authority so you issue short-lived host and user certs instead of copying authorized_keys to five hundred machines. Hardening is configuration, not mystery: /etc/ssh/sshd_config plus a reload.

This note walks client and server settings, shows CA-signed user cert flow, and warns about lockout — always keep a console session open while testing. For broader host defense, continue with Linux hardening; for detecting brute force and lateral movement, see Linux detection engineering.

SSH hardening rollout

Validate config with sshd -t before reload. Test from a second session. Roll out CA before disabling old keys.

1Backup sshd_configand existing keys2Disable passwordsPasswordAuthentication no3Restrict usersAllowGroups ssh-users4Modern cipherschacha20-poly1305, curve255195Deploy SSH CAsign user certs with expiry6Trust CA in sshdTrustedUserCAKeys7Reload + verifysshd -t && systemctl reload sshd

Core sshd_config settings

Set PermitRootLogin no — use sudo on a named account. Disable empty passwords and challenge-response. MaxAuthTries 3 slows brute force. Pair with fail2ban or network-level rate limits; sshd alone will still log noise.

AllowUsers or AllowGroups restrict which identities may authenticate at all — useful when LDAP returns every employee but only ssh-users should reach production. LoginGraceTime 30 shortens hung connection windows. Disable agent forwarding (AllowAgentForwarding no) on jump hosts unless you explicitly need it; forwarding is a lateral movement path.

/etc/ssh/sshd_config.d/99-hardening.conf
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
AllowGroups ssh-users
MaxAuthTries 3
X11Forwarding no
KexAlgorithms curve25519-sha256,[email protected]

SSH CA for user certificates

Generate a CA key offline. Sign user public keys into short-lived certificates with -O permit-pty,force-command only if you need restrictions. On each host, set TrustedUserCAKeys /etc/ssh/ca.pub. Revocation is centralized — rotate the CA or publish a KRL instead of editing every authorized_keys.

Host certificates (HostCertificate signed by a host CA) let clients trust servers without StrictHostKeyChecking=no in scripts. Vault, step-ca, and small internal CAs automate signing. Offboarding becomes revoking the user cert template or removing the principal from the next issued cert — not grep across fleet authorized_keys.

sign-user-cert.sh
# On CA workstation (offline)
ssh-keygen -t ed25519 -f ssh_ca -C "corp-user-ca"
# Sign alice's key — valid 8 hours
ssh-keygen -s ssh_ca -I alice@corp -n alice,admin \
-V +8h -O permit-pty id_ed25519.pub
# On server: TrustedUserCAKeys /etc/ssh/ca.pub
bash — validate before reloadlive
sshd -t -f /etc/ssh/sshd_config
Syntax OK
Offering public key: ED25519-CERT ...
Authenticating with public key ...
Welcome — cert auth succeeded
Test from two sessions before closing the old one
A typo in KexAlgorithms or AllowGroups can lock every admin out except the serial console. Run `sshd -t`, reload, then verify login from a second terminal before disconnecting your safety session. Keep break-glass keys in a vault — not in sshd_config comments.
Keys vs certificates
Static authorized_keys
Fine for small fleets
Per-user file drift
Painful offboarding
No expiry by default
CA-signed certs
Central issue and revoke
Short Validity intervals
One TrustedUserCAKeys file
Pairs with Vault/step-ca

Where this goes next

Layer network controls — allowlist admin IPs with nftables or security groups, forward sshd logs to SIEM, and alert on new keys in authorized_keys if you have not migrated to CA yet. Linux hardening covers the full stack; Linux detection engineering shows auditd and journal rules for SSH anomalies.

Bastion hosts deserve the same cipher suite as internal servers — weak edge sshd undermines the whole model. Rotate host keys after imaging clones; duplicate host keys break StrictHostKeyChecking for automation.

Go deeper in a courseLinux hardeningSSH, firewall, systemd sandboxing, and production host baselines.View course

Related posts