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.
| Method | Trust anchor | Strengths | Trade-offs | Use for |
|---|---|---|---|---|
| Password | Local or directory password via PAM | No client setup | Brute force, credential stuffing, phishing | Nothing on internet-facing hosts; disable |
| Public key (authorized_keys) | Per-account key file | Strong cryptography, works offline | Keys never expire, sprawl, no central revocation | Small estates, break-glass |
| User certificate | CA public key in TrustedUserCAKeys | Expiry, principals, embedded restrictions, key ID in logs | Needs a CA and issuance workflow | Human and automation access at scale |
| Hardware-backed key (sk-ssh-ed25519, sk-ecdsa) | FIDO authenticator | Private key not extractable, touch required | Unsuitable for unattended automation | Administrators |
| GSSAPI (Kerberos) | KDC tickets | Single sign-on in AD or MIT realms | Depends on keytab and realm hygiene | Directory-integrated estates |
| Keyboard-interactive with MFA | PAM module (OTP, push) | Adds a second factor | Prompts break automation; phishable OTP | Combined 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. Setnoand require named accounts that elevate with sudo, so every root action traces to a person. Useforced-commands-onlyonly 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-adminsso 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-interactivefor the admin group through aMatch Group ssh-adminsblock. - Bastions and privileged session management: route administrative SSH through a hardened jump host or PAM proxy that records sessions, and use
Match Addressso 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-sftpandChrootDirectoryin 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 addfrom="10.20.0.0/24"andcommand="/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-addressand-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/%uwith root ownership stops users and compromised service accounts adding their own keys, and makes the file set easy to audit.AuthorizedKeysCommand(with a dedicatedAuthorizedKeysCommandUser) 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/%umaps certificate principals to accounts, so a role principal such asdb-admincan be granted to the right accounts on the right hosts. - Revocation: publish a key revocation list built with
ssh-keygen -kand reference it withRevokedKeys; test withssh-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.publets clients trust any host signed by the host CA (an@cert-authorityline 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.
| Signal | Log evidence | Possible meaning |
|---|---|---|
| Many "Failed password" or "Invalid user" lines from one source | sshd auth log | Brute force or credential stuffing (T1110) |
| Successful login after many failures | Failure burst followed by "Accepted" | Guessed credential (T1078) |
| "Accepted publickey" with an unknown fingerprint | VERBOSE log fingerprint not in the key inventory | Planted key (T1098.004) |
| Service account login from a new source or interactive PTY | Source address, session type | Stolen automation key (T1552.004) |
| New or changed authorized_keys file | auditd or FIM event | Persistence |
| Port forwarding requests on hosts that should not forward | VERBOSE channel messages | Tunnelling or lateral movement (T1021.004) |
Metrics
- Password-free hosts: percentage of servers where
sshd -Tshows 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.
| Setting | Default | Hardened value | Reason |
|---|---|---|---|
| PermitRootLogin | prohibit-password | no | Named accounts and sudo |
| PasswordAuthentication | yes | no | Removes brute force |
| KbdInteractiveAuthentication | yes | no, or only in AuthenticationMethods for MFA | Stops PAM password prompts |
| AllowGroups | unset | ssh-users ssh-admins | Explicit access grant |
| DisableForwarding | unset | yes (re-enable per Match) | Blocks TCP, agent, X11 and StreamLocal tunnels |
| PermitTunnel / GatewayPorts | no / no | no / no | Keep defaults |
| PermitUserEnvironment | no | no | Prevents environment injection |
| MaxAuthTries | 6 | 3 | Fewer guesses per connection |
| LoginGraceTime | 120 | 30 | Limits unauthenticated connections |
| MaxStartups | 10:30:100 | 10:30:60 | Earlier random drop under load |
| ClientAliveInterval / CountMax | 0 / 3 | 300 / 2 | Drops dead sessions |
| LogLevel | INFO | VERBOSE | Key fingerprints in logs |
| StrictModes | yes | yes | Rejects world-writable key files |
| AuthorizedKeysFile | .ssh/authorized_keys .ssh/authorized_keys2 | /etc/ssh/authorized_keys/%u, or none with certificates | Central, root-owned key files |
| TrustedUserCAKeys / RevokedKeys | unset | CA file and KRL file | Certificate 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
- Inventory: run
sshd -Ton every host to capture the effective configuration, OpenSSH version and enabled methods; list all authorized_keys files and their owners. - Prepare access: make sure every human and automation account has a working key or certificate and is in an Allow group before passwords go.
- Validate before reload:
sshd -tchecks syntax and host keys;sshd -T -C user=deploy,host=ci01,addr=10.20.0.5shows the configuration a specific connection will receive after Match rules. - 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.
- Roll out in rings: non-production, then internal production, then internet-facing, watching authentication failures per ring.
- Roll back: remove or rename the drop-in and reload; configuration management should hold the previous version so rollback is one change.
Framework mapping
| Framework | Reference | SSH controls |
|---|---|---|
| NIST SP 800-53 Rev. 5 | AC-17 Remote Access, IA-5 Authenticator Management, SC-8, SC-13, AU-2, AU-12, CM-6 | Restricted remote access, managed keys, strong algorithms, logged sessions, baseline configuration |
| NIST CSF 2.0 | PR.AA-05, PR.PS-01, PR.PS-04 | Reviewed access, configuration management, log generation |
| CIS Controls v8.1 | 4.1, 4.6 Securely manage enterprise assets, 5.2, 6.5 Require MFA for administrative access, 8.2 | Baseline, secure management protocols, MFA for admins, audit logs |
| MITRE ATT&CK | T1021.004, T1098.004, T1110, T1078, T1552.004 | Detections 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
- OpenBSD manual pages: sshd_config(5), OpenSSH daemon configuration file
- OpenBSD manual pages: sshd(8), OpenSSH daemon and authorized_keys format
- OpenBSD manual pages: ssh-keygen(1), certificates and key revocation lists
- OpenSSH: Release notes
- OpenSSH: OpenSSH 9.8 release notes (PerSourcePenalties)
- NIST: IR 7966, Security of Interactive and Automated Access Management Using Secure Shell (SSH)
- MITRE ATT&CK: SSH Authorized Keys
- NIST: SP 800-53 Rev. 5
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