Join our Newsletter — 33% off our NHI Course
Home› Guides› OpenSSH Server Hardening Guide: sshd_config, Ciphers, Certificates and…
Guide Endpoint Security

OpenSSH Server Hardening Guide: sshd_config, Ciphers, Certificates and Logging

PDF for newsletter subscribers · free to read online

← All guides
By NHI Mgmt Group, edited by Lalit Choda Updated 8 November 2026 13 min read
On this page

The OpenSSH server is the front door to almost every Linux and Unix estate, and its defaults are built for compatibility rather than for a hardened production network. Out of the box, sshd accepts passwords, allows TCP and agent forwarding, trusts any key a user drops into authorized_keys and logs at a level that does not record which key was used. This guide works through sshd_config setting by setting: authentication and access control, forwarding, cryptographic algorithms, user and host certificates, automation accounts, logging and a safe rollout. It is for Linux and platform engineers, security architects and auditors. Key lifecycle and discovery are covered in the SSH Key Management Guide; this page focuses on the daemon.

This is an independent guide from NHI Mgmt Group, based on the OpenSSH project's public documentation as of November 2026. It is not sponsored or reviewed by the OpenSSH project. Product features change, so confirm settings against the OpenSSH project's current documentation.

Key takeaways

  • Turn off passwords and keyboard-interactive. PasswordAuthentication and KbdInteractiveAuthentication both default to yes; set them to no once key or certificate login works for every account.
  • Restrict who can log in and what they can do. AllowGroups, PermitRootLogin no and DisableForwarding in a default-deny posture, with Match blocks to grant exceptions.
  • Move from static keys to certificates. TrustedUserCAKeys with AuthorizedPrincipalsFile and short validity periods replaces sprawling authorized_keys files with central, expiring trust.
  • Keep the daemon current. Apply OpenSSH security updates promptly using the release notes; OpenSSH 10.0 made the post-quantum hybrid mlkem768x25519-sha256 the default key exchange and removed DSA.
  • Log the key, not just the user. LogLevel VERBOSE records key fingerprints and certificate key IDs so a login can be traced to a credential and its owner.

How identity and access work in OpenSSH

sshd authenticates in two directions. The server proves its identity with a host key (or host certificate) that the client checks against known_hosts or a trusted host CA. The client proves the user's identity with one or more methods: publickey, password, keyboard-interactive (usually PAM, including OTP prompts), gssapi-with-mic (Kerberos) and hostbased. After authentication the account's Unix identity, PAM account and session modules and any ForceCommand or ChrootDirectory decide what the session can do.

MethodTrust anchorStrengthsTrade-offsUse for
PasswordLocal or directory password via PAMNo client setupBrute force, credential stuffing, phishingNothing on internet-facing hosts; disable
Public key (authorized_keys)Per-account key fileStrong cryptography, works offlineKeys never expire, sprawl, no central revocationSmall estates, break-glass
User certificateCA public key in TrustedUserCAKeysExpiry, principals, embedded restrictions, key ID in logsNeeds a CA and issuance workflowHuman and automation access at scale
Hardware-backed key (sk-ssh-ed25519, sk-ecdsa)FIDO authenticatorPrivate key not extractable, touch requiredUnsuitable for unattended automationAdministrators
GSSAPI (Kerberos)KDC ticketsSingle sign-on in AD or MIT realmsDepends on keytab and realm hygieneDirectory-integrated estates
Keyboard-interactive with MFAPAM module (OTP, push)Adds a second factorPrompts break automation; phishable OTPCombined with publickey via AuthenticationMethods

AuthenticationMethods publickey,keyboard-interactive requires both methods in sequence, which is the standard way to add MFA for humans while keeping a key as the first factor. See the SSH Protocol and Certificate Authority Guide for the protocol layers.

Admin roles and privileged access

  • PermitRootLogin: the default is prohibit-password, which still allows root with a key. Set no and require named accounts that elevate with sudo, so every root action traces to a person. Use forced-commands-only only for a legacy job you cannot yet move. See the sudo and sudoers Security Guide.
  • AllowGroups and AllowUsers: with no Allow directive, every account with a valid shell and credential can log in. Set AllowGroups ssh-users ssh-admins so membership is a deliberate, reviewable grant. DenyUsers and DenyGroups take precedence over the Allow lists.
  • Administrator MFA: require hardware-backed keys or AuthenticationMethods publickey,keyboard-interactive for the admin group through a Match Group ssh-admins block.
  • Bastions and privileged session management: route administrative SSH through a hardened jump host or PAM proxy that records sessions, and use Match Address so production servers accept admin logins only from those sources. See the Privileged Session Management Guide and the Unix and Linux Privileged Access Guide.
  • Restricted users: file transfer partners should get ForceCommand internal-sftp and ChrootDirectory in a Match block, with forwarding disabled, rather than a shell.

Integrations, API tokens and service accounts

SSH is the most common machine-to-machine credential in Unix estates: backup agents, configuration management, deployment pipelines, file transfer and monitoring all log in with keys. NIST IR 7966 noted that "the security of SSH key-based access has been largely ignored", and the pattern still holds: automation keys are usually unencrypted, never rotated and unrestricted.

  • Restrict every automation key: in authorized_keys, prefix the key with restrict (which disables port, agent and X11 forwarding, PTY allocation and ~/.ssh/rc) and add from="10.20.0.0/24" and command="/usr/local/bin/backup-receive". The client's requested command is then available to the forced command in SSH_ORIGINAL_COMMAND for validation.
  • Expire keys: the expiry-time="YYYYMMDD" option stops sshd accepting a key after a date, a cheap control for contractor or project keys.
  • Prefer short-lived certificates for pipelines: a CI job can request a certificate valid for minutes, with -O force-command, -O source-address and -O no-pty, instead of holding a long-lived private key as a secret. See the Secrets Management Guide.
  • Move key files out of home directories: AuthorizedKeysFile /etc/ssh/authorized_keys/%u with root ownership stops users and compromised service accounts adding their own keys, and makes the file set easy to audit. AuthorizedKeysCommand (with a dedicated AuthorizedKeysCommandUser) can fetch keys from a directory instead.
  • Do not forward agents into shared hosts: anyone with root on the intermediate host can use a forwarded agent. Use ProxyJump on the client instead.

Persistence through added keys is MITRE ATT&CK T1098.004 SSH Authorized Keys, and theft of unprotected private keys is T1552.004 Private Keys. See the Linux Service Accounts and Keytab Management Guide.

User certificates and host certificates

  • User CA: sign keys with ssh-keygen -s user_ca -I alice@corp -n alice,deploy -V +8h id_ed25519.pub. The key ID (-I) is written to sshd logs and can be used to revoke the certificate. Without -V a certificate is valid indefinitely, so always set it.
  • Principals: AuthorizedPrincipalsFile /etc/ssh/principals/%u maps certificate principals to accounts, so a role principal such as db-admin can be granted to the right accounts on the right hosts.
  • Revocation: publish a key revocation list built with ssh-keygen -k and reference it with RevokedKeys; test with ssh-keygen -Q. A missing or unreadable revocation file should be treated as a deployment failure.
  • Host certificates: HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pub lets clients trust any host signed by the host CA (an @cert-authority line in known_hosts), which removes trust-on-first-use prompts and makes host key rotation routine. Without host certificates, replacing a host key means every client must edit known_hosts by hand, with a risk of accepting an impostor's key.

Logging and detection

  • LogLevel VERBOSE: the default INFO records the user and source address; VERBOSE adds the fingerprint (SHA256 by default, set by FingerprintHash) of the key or certificate used, which is the only way to tell which of several authorized keys logged in.
  • Facility and forwarding: sshd logs to SyslogFacility AUTH by default (auth.log, secure or the journal). Forward it centrally; local logs are the first thing an intruder edits. See the Linux Logging and auditd for Defenders Guide.
  • File integrity: monitor sshd_config, sshd_config.d, host keys, TrustedUserCAKeys, principals files and every authorized_keys file with auditd watches or FIM.
  • Brute-force control: PerSourcePenalties, added in OpenSSH 9.8 and on by default, penalises source addresses that fail authentication, crash the server or connect without authenticating. Hosts with many users behind NAT may need PerSourcePenaltyExemptList.
SignalLog evidencePossible meaning
Many "Failed password" or "Invalid user" lines from one sourcesshd auth logBrute force or credential stuffing (T1110)
Successful login after many failuresFailure burst followed by "Accepted"Guessed credential (T1078)
"Accepted publickey" with an unknown fingerprintVERBOSE log fingerprint not in the key inventoryPlanted key (T1098.004)
Service account login from a new source or interactive PTYSource address, session typeStolen automation key (T1552.004)
New or changed authorized_keys fileauditd or FIM eventPersistence
Port forwarding requests on hosts that should not forwardVERBOSE channel messagesTunnelling or lateral movement (T1021.004)

Metrics

  • Password-free hosts: percentage of servers where sshd -T shows passwordauthentication no and kbdinteractiveauthentication no (or MFA-only).
  • Certificate coverage: percentage of logins by certificate rather than static key.
  • Unknown keys: count of authorized keys with no recorded owner (target zero).
  • Patch latency: days from an OpenSSH security release to deployment on internet-facing hosts.
  • Forwarding exceptions: number of Match blocks re-enabling forwarding, each with an owner.

Hardening baseline

A baseline for a current OpenSSH release. Place it in a drop-in such as /etc/ssh/sshd_config.d/10-hardening.conf where your distribution uses Include; for most keywords the first value obtained wins, so the drop-in must load before conflicting lines.

SettingDefaultHardened valueReason
PermitRootLoginprohibit-passwordnoNamed accounts and sudo
PasswordAuthenticationyesnoRemoves brute force
KbdInteractiveAuthenticationyesno, or only in AuthenticationMethods for MFAStops PAM password prompts
AllowGroupsunsetssh-users ssh-adminsExplicit access grant
DisableForwardingunsetyes (re-enable per Match)Blocks TCP, agent, X11 and StreamLocal tunnels
PermitTunnel / GatewayPortsno / nono / noKeep defaults
PermitUserEnvironmentnonoPrevents environment injection
MaxAuthTries63Fewer guesses per connection
LoginGraceTime12030Limits unauthenticated connections
MaxStartups10:30:10010:30:60Earlier random drop under load
ClientAliveInterval / CountMax0 / 3300 / 2Drops dead sessions
LogLevelINFOVERBOSEKey fingerprints in logs
StrictModesyesyesRejects world-writable key files
AuthorizedKeysFile.ssh/authorized_keys .ssh/authorized_keys2/etc/ssh/authorized_keys/%u, or none with certificatesCentral, root-owned key files
TrustedUserCAKeys / RevokedKeysunsetCA file and KRL fileCertificate trust with revocation

Cryptographic algorithms

Current OpenSSH defaults are sound: ciphers [email protected], AES-GCM and AES-CTR; key exchange led by mlkem768x25519-sha256 and sntrup761x25519-sha512, then curve25519-sha256 and the NIST ECDH curves. Rather than pasting a fixed list that will age, remove what you do not want with the - prefix, for example MACs -hmac-sha1,[email protected],[email protected],[email protected], and raise RequiredRSASize from its 1024-bit default to 3072. Prefer Ed25519 host and user keys and remove unused host key types. OpenSSH 10.1 added a client warning when a non-post-quantum key exchange is negotiated, and 10.6 added the equivalent server option, so a hard-coded list without the hybrid algorithms will start producing warnings. On RHEL-family systems, system-wide crypto policies set these lists; change the policy rather than editing sshd_config.

Rollout and rollback

  1. Inventory: run sshd -T on every host to capture the effective configuration, OpenSSH version and enabled methods; list all authorized_keys files and their owners.
  2. Prepare access: make sure every human and automation account has a working key or certificate and is in an Allow group before passwords go.
  3. Validate before reload: sshd -t checks syntax and host keys; sshd -T -C user=deploy,host=ci01,addr=10.20.0.5 shows the configuration a specific connection will receive after Match rules.
  4. Pilot with a safety net: keep an existing session open, reload sshd (existing sessions survive) and test a new login from a second terminal. Use out-of-band console access for the first ring.
  5. Roll out in rings: non-production, then internal production, then internet-facing, watching authentication failures per ring.
  6. Roll back: remove or rename the drop-in and reload; configuration management should hold the previous version so rollback is one change.

Framework mapping

FrameworkReferenceSSH controls
NIST SP 800-53 Rev. 5AC-17 Remote Access, IA-5 Authenticator Management, SC-8, SC-13, AU-2, AU-12, CM-6Restricted remote access, managed keys, strong algorithms, logged sessions, baseline configuration
NIST CSF 2.0PR.AA-05, PR.PS-01, PR.PS-04Reviewed access, configuration management, log generation
CIS Controls v8.14.1, 4.6 Securely manage enterprise assets, 5.2, 6.5 Require MFA for administrative access, 8.2Baseline, secure management protocols, MFA for admins, audit logs
MITRE ATT&CKT1021.004, T1098.004, T1110, T1078, T1552.004Detections and mitigations in the table above

Common misconfigurations

  • Disabling PasswordAuthentication but not KbdInteractiveAuthentication: with UsePAM enabled, PAM can still prompt for a password through keyboard-interactive, so the server still accepts passwords.
  • Settings shadowed by drop-ins or Match order: a cloud image's drop-in sets PasswordAuthentication yes and loads first, or a Match block is placed above global lines. Always verify with sshd -T, not by reading the file.
  • Unrestricted automation keys: a backup key with no from= or command= gives a full shell to anyone who copies it, often with sudo rights.
  • Certificates without expiry or revocation: signing with no -V produces certificates valid indefinitely, and a TrustedUserCAKeys without RevokedKeys cannot withdraw a leaked one.
  • Trusting the build chain blindly: sshd can load libraries through distribution patches, for example liblzma where sshd is linked to systemd. Track what sshd links against, take packages only from signed distribution repositories and keep rolling or development releases off production. See the Linux Package Signing and Repository Trust Guide.
  • Running unpatched sshd on the internet: Apply security updates promptly. Limit exposure with firewalls or a VPN and patch internet-facing sshd first.

Practitioner checklist

  • Capture sshd -T output and the OpenSSH version for every host and compare it to the baseline.
  • Set PermitRootLogin no, PasswordAuthentication no and KbdInteractiveAuthentication no (or MFA only via AuthenticationMethods).
  • Restrict logins with AllowGroups and require MFA or hardware-backed keys for the admin group.
  • Set DisableForwarding yes globally and re-enable forwarding only in owned Match blocks.
  • Prefix every automation key with restrict, from= and command=, or move it to short-lived certificates.
  • Deploy a user CA with AuthorizedPrincipalsFile, a validity on every certificate and a published RevokedKeys file.
  • Issue host certificates and distribute the host CA in known_hosts to end trust-on-first-use.
  • Set LogLevel VERBOSE, forward auth logs centrally and watch authorized_keys and sshd configuration with FIM.
  • Patch OpenSSH within a defined window, internet-facing hosts first, and remove legacy algorithms with the minus-prefix syntax.

Standards and references

Related NHI Mgmt Group resources: SSH Key Management Guide · SSH Protocol and Certificate Authority Guide · Linux Server Hardening Guide · Unix and Linux Privileged Access Guide

PDF for subscribers

Take this guide with you

Every section, table and checklist in one PDF, with links to the sources and related guides. Subscribe to our weekly NHI & AI Identity Journal and we’ll email you a download link.

Free weekly newsletter

Subscribe to the NHI & AI Identity Journal

The latest on NHI and Agentic AI security – articles, research, breaches, news and events every week.

Bonus 33% off our NHI Course when you subscribe.

NHIMG Editorial Note
Researched and written by the NHI Mgmt Group editorial team using AI tools, under the editorial direction of Lalit Choda. Facts are drawn from the sources listed on this page and checked by our automated quality process. Last updated 8 November 2026. Spotted an error? Use our contact page.
NHI Mgmt Group, the independent authority on Non-Human Identity, IAM and Agentic AI security. nhimg.org

PDF Downloads for Newsletter Subscribers

Get the guide

Enter your details and we’ll email you a download link.

The full guide is free to read online. The PDF is a thank you for subscribing.

Fill in all fields marked * and tick the PDF box to continue.