sshd_config
Configure the OpenSSH server: listening, authentication, forwarding, access control and logging.
Before you run
The server configuration is distinct from the client ssh_config. Paths, supported options and defaults depend on operating system and OpenSSH version. Keep an existing administrative session open and a recovery path available. Before applying changes, validate the actual configuration with sshd -t and inspect effective settings with sshd -T; these commands may require administrator privileges. Verify a second login before closing the original session. Do not copy example values blindly.
After applying changes, verify that you can sign in and that the intended behavior works in a new SSH session. Keep the current session open until verification succeeds, so you can restore the configuration if necessary.
Examples
Example server configuration. Adapt authentication, paths and access rules to your environment.
Port 22
PermitRootLogin no
PubkeyAuthentication yes
AllowTcpForwarding yesValidate syntax and inspect effective server settings before applying changes.
sudo sshd -t
sudo sshd -TOptions and examples
PortCommonListening TCP port; multiple Port directives are allowed. Ensure the firewall and clients permit the chosen port.
Port 2222ListenAddressCommonLocal address on which sshd listens. An address can include a port; ensure it exists on the server.
ListenAddress 192.0.2.10AddressFamilySelect address family: any, inet for IPv4, or inet6 for IPv6.
AddressFamily inetHostKeyCommonPath to a server private host key; this is not a user's authentication key. Protect the private file.
HostKey /etc/ssh/ssh_host_ed25519_keyHostCertificatePath to a server host certificate matching a configured host key.
HostCertificate /etc/ssh/ssh_host_ed25519_key-cert.pubPasswordAuthenticationCommonAllow or deny password authentication. Verify another login method before disabling it.
PasswordAuthentication noPubkeyAuthenticationCommonAllow or deny public key authentication. Server permissions and authorized keys still apply.
PubkeyAuthentication yesKbdInteractiveAuthenticationCommonAllow keyboard-interactive authentication. The prompts and available methods depend on the server and authentication backend.
KbdInteractiveAuthentication yesAuthenticationMethodsCommonRequire one of the space-separated method lists; every comma-separated method in a list must succeed. Each method must also be enabled.
AuthenticationMethods publickey,keyboard-interactivePermitRootLoginCommonControl root login: yes, prohibit-password, forced-commands-only, or no. Test an alternative administrative login first.
PermitRootLogin noPermitEmptyPasswordsAllow accounts with empty passwords to authenticate using password authentication. Enabling this is unsafe.
PermitEmptyPasswords noAuthorizedKeysFileCommonPaths to files containing authorized public keys. Relative paths are resolved from the user's home directory; tokens are supported.
AuthorizedKeysFile .ssh/authorized_keysStrictModesCommonCheck ownership and permissions of user files and home directories before accepting login.
StrictModes yesAllowUsersCommonAllow only the listed user name patterns; USER@HOST patterns can constrain the origin. Account access is also subject to other restrictions.
AllowUsers alice bobDenyUsersDeny matching user name patterns. Deny rules take precedence over corresponding allow rules.
DenyUsers guestAllowGroupsAllow only users in matching named groups, subject to other access rules.
AllowGroups sshusersDenyGroupsDeny users in matching named groups; group names, not numeric IDs, are used.
DenyGroups restrictedAllowTcpForwardingCommonControl TCP forwarding: yes or all, no, local, or remote. This alone cannot prevent forwarding by users with unrestricted shell access.
AllowTcpForwarding localDisableForwardingDisable forwarding features, overriding other forwarding settings. This can break tunnels and agent or X11 forwarding.
DisableForwarding yesGatewayPortsCommonControl remote forwarding bind addresses: no binds loopback, yes binds wildcard, and clientspecified permits client-selected addresses. Exposing ports has security implications.
GatewayPorts noPermitOpenRestrict destinations for local TCP forwarding; use host:port entries, any, or none. Names are not resolved for matching.
PermitOpen db.example.com:5432PermitListenRestrict listening addresses and ports for remote forwarding; GatewayPorts also affects binding.
PermitListen localhost:18080AllowAgentForwardingAllow SSH authentication-agent forwarding. A remote process with access to the agent socket can request signatures.
AllowAgentForwarding noAllowStreamLocalForwardingControl Unix-domain socket forwarding: yes or all, no, local, or remote.
AllowStreamLocalForwarding noX11ForwardingEnable X11 display forwarding. Enable only where needed and understand the remote display access risk.
X11Forwarding noMaxAuthTriesCommonMaximum authentication attempts per connection before disconnecting. The server may log failures earlier.
MaxAuthTries 4MaxSessionsCommonMaximum shell, login, or subsystem sessions per SSH connection. Setting zero prevents sessions but may still permit forwarding.
MaxSessions 10MaxStartupsCommonLimit unauthenticated connections. The start:rate:full form progressively rejects connections under load.
MaxStartups 10:30:100LoginGraceTimeCommonTime allowed for authentication; a duration of zero means no time limit.
LoginGraceTime 60sClientAliveIntervalCommonInterval in seconds for encrypted SSH-level client-alive probes; zero disables these probes.
ClientAliveInterval 30ClientAliveCountMaxCommonNumber of unanswered SSH-level client-alive probes tolerated before disconnecting. Use with ClientAliveInterval.
ClientAliveCountMax 3TCPKeepAliveControl TCP keepalive messages. These are separate from encrypted SSH client-alive probes.
TCPKeepAlive yesUsePAMCommonEnable PAM integration on builds that support it. PAM policy and available authentication methods vary by system.
UsePAM yesPermitTTYAllow allocation of a pseudo-terminal. Disabling it affects interactive sessions.
PermitTTY yesForceCommandReplace the requested command with a fixed command. Validate access and restrictions carefully before enabling.
ForceCommand internal-sftpSubsystemCommonDefine a named subsystem and its command; internal-sftp is the built-in SFTP server.
Subsystem sftp internal-sftpChrootDirectoryConfine a session to a directory after authentication. Directory ownership and permissions are strictly checked; provision required files for the intended session.
ChrootDirectory /srv/sftp/%uMatchCommonStart a conditional block for matching users, groups, addresses, or other supported criteria. Only certain directives are permitted inside it.
Match User sftpuser
ForceCommand internal-sftpIncludeCommonInclude configuration files by path or glob. Ordering matters because the first obtained value generally applies.
Include /etc/ssh/sshd_config.d/*.confLogLevelCommonSet logging verbosity, such as QUIET, FATAL, ERROR, INFO, VERBOSE, or DEBUG. Detailed logs may expose sensitive information.
LogLevel INFOSyslogFacilityChoose the syslog facility used for SSH server messages; system logging configuration determines where they appear.
SyslogFacility AUTHBannerSend the contents of a specified file before authentication. Use none to disable a configured banner.
Banner /etc/issue.netAcceptEnvAllow named client-supplied environment variables. Some variables can bypass restricted environments, so allow only what is needed.
AcceptEnv LANG LC_*PermitUserEnvironmentControl user-provided environment settings. Enabling them can bypass restrictions through environment variables.
PermitUserEnvironment noPrintMotdControl whether sshd prints the message of the day at interactive login. PAM or another service may also print it.
PrintMotd noCompressionControl compression. Supported values and timing vary by OpenSSH version.
Compression noRekeyLimitSet the data threshold and optionally the time interval for rekeying. Use values appropriate for the server version.
RekeyLimit 1G 1hCiphersSelect permitted encryption algorithms. Replacing the default list may reduce compatibility; use ssh -Q cipher to inspect client-supported algorithms.
Ciphers aes256-gcm@openssh.com,aes128-gcm@openssh.comKexAlgorithmsSelect key exchange algorithms. Restricting this list can break clients; verify support on both sides.
KexAlgorithms curve25519-sha256PubkeyAcceptedAlgorithmsSelect permitted public-key signature algorithms for user authentication. Verify compatibility before changing the default list.
PubkeyAcceptedAlgorithms ssh-ed25519HostKeyAlgorithmsSelect host-key signature algorithms offered by the server. The configured host key must support the chosen algorithm.
HostKeyAlgorithms ssh-ed25519TrustedUserCAKeysFile containing trusted user certificate authority public keys for certificate authentication.
TrustedUserCAKeys /etc/ssh/user_ca.pubRevokedKeysFile containing revoked public keys or a key revocation list. A missing or unreadable configured file can prevent public-key authentication.
RevokedKeys /etc/ssh/revoked_keysAuthorizedPrincipalsFileFile listing principals permitted for a user certificate signed by a trusted CA; token expansion is supported.
AuthorizedPrincipalsFile /etc/ssh/auth_principals/%uVersionAddendumAppend text to the SSH protocol banner; none disables the added text.
VersionAddendum noneAuthorizedKeysCommandRun a trusted, root-owned program to obtain public keys. Configure its execution account and follow the manual's ownership requirements.
AuthorizedKeysCommand /usr/local/libexec/ssh-keys %uAuthorizedKeysCommandUserAccount used to run AuthorizedKeysCommand; a dedicated account is recommended.
AuthorizedKeysCommandUser sshkeysAuthorizedPrincipalsCommandRun a trusted program to obtain permitted certificate principals. Configure its execution account separately.
AuthorizedPrincipalsCommand /usr/local/libexec/ssh-principals %uAuthorizedPrincipalsCommandUserAccount used to run AuthorizedPrincipalsCommand; use a dedicated account.
AuthorizedPrincipalsCommandUser sshprincipalsCASignatureAlgorithmsRestrict certificate authority signature algorithms accepted for SSH certificates. Verify CA and client compatibility before changes.
CASignatureAlgorithms ssh-ed25519ChannelTimeoutExpire inactive channels by channel type and duration; availability and supported channel types depend on version. Expiry need not terminate the SSH connection.
ChannelTimeout session=1hExposeAuthInfoExpose authentication information through a temporary file referenced by SSH_USER_AUTH; consider access to authentication details.
ExposeAuthInfo noFingerprintHashSelect the hash used for key fingerprints, such as sha256 or md5. Prefer SHA-256.
FingerprintHash sha256GSSAPIAuthenticationControl GSSAPI user authentication when supported by the server build.
GSSAPIAuthentication noGSSAPICleanupCredentialsControl whether delegated GSSAPI credentials are destroyed at logout; build support varies.
GSSAPICleanupCredentials yesGSSAPIDelegateCredentialsControl storing delegated GSSAPI credentials for user sessions when supported.
GSSAPIDelegateCredentials noGSSAPIStrictAcceptorCheckControl whether the server requires the correct GSSAPI host identity. Disabling verification has security implications.
GSSAPIStrictAcceptorCheck yesHostbasedAcceptedAlgorithmsSelect algorithms accepted for host-based authentication. Availability varies by OpenSSH version.
HostbasedAcceptedAlgorithms ssh-ed25519HostbasedAuthenticationControl host-based authentication; it requires additional trust and host configuration.
HostbasedAuthentication noHostbasedUsesNameFromPacketOnlyControl whether host-based authentication uses the name supplied by the client instead of DNS. Review the trust implications.
HostbasedUsesNameFromPacketOnly noHostKeyAgentSpecify the agent socket used to access host private keys. The agent and its socket must be available to sshd.
HostKeyAgent /run/ssh-hostkey-agent.sockIgnoreRhostsControl use of per-user rhosts or shosts files for host-based authentication; accepted values vary by version.
IgnoreRhosts yesIgnoreUserKnownHostsControl whether user-specific known_hosts files are ignored during host-based authentication.
IgnoreUserKnownHosts yesKerberosAuthenticationControl Kerberos password authentication when built and configured with Kerberos support.
KerberosAuthentication noKerberosGetAFSTokenControl obtaining an AFS token for a Kerberos-authenticated user where the build supports it.
KerberosGetAFSToken noKerberosOrLocalPasswdControl whether failed Kerberos password validation falls back to local password authentication.
KerberosOrLocalPasswd noKerberosTicketCleanupControl removal of a user's Kerberos ticket cache at logout where supported.
KerberosTicketCleanup yesLogVerboseOverride logging verbosity for matching source locations. It is intended for troubleshooting and may expose sensitive information.
LogVerbose kex.c:*:1000ModuliFilePath to the moduli file used for Diffie-Hellman group exchange; maintain it according to platform guidance.
ModuliFile /etc/ssh/moduliPAMServiceNameSelect the PAM service name on builds that support this directive; PAM policy for the selected service must exist.
PAMServiceName sshdPermitTunnelControl tun device forwarding: yes, point-to-point, ethernet, or no. Additional system privileges and configuration may be required.
PermitTunnel noPermitUserRCControl execution of the user's SSH rc file. Disabling it can affect user session setup.
PermitUserRC noPerSourceMaxStartupsLimit simultaneous unauthenticated connections per source address or source group; version support varies.
PerSourceMaxStartups 10PerSourceNetBlockSizeSet IPv4 and IPv6 prefix lengths used to group sources for per-source connection limits.
PerSourceNetBlockSize 32:128PerSourcePenaltiesConfigure penalties for problematic sources. Supported penalty types, values, and defaults vary by OpenSSH version.
PerSourcePenalties noPerSourcePenaltyExemptListList source addresses or CIDR ranges exempt from per-source penalties; ensure exemptions are narrowly scoped.
PerSourcePenaltyExemptList 192.0.2.0/24PidFilePath to the server process ID file. Ensure the service manager and permissions agree with this path.
PidFile /run/sshd.pidPrintLastLogControl printing the previous login time for interactive logins. Availability may depend on platform support.
PrintLastLog yesPubkeyAuthOptionsSet public-key authentication options, including security-key touch or verification requirements when supported.
PubkeyAuthOptions touch-requiredRefuseConnectionRefuse a connection, typically inside a Match block. Availability varies by version.
Match User blocked
RefuseConnection yesRequiredRSASizeSet the minimum RSA key size accepted by sshd. Lower values may weaken security and some versions impose a minimum.
RequiredRSASize 3072RDomainSelect a routing domain for the session on platforms that support routing domains. This is platform-specific.
RDomain 1SecurityKeyProviderPath to a FIDO security-key middleware library; leaving it unset uses the built-in support where available.
SecurityKeyProvider /usr/local/lib/libsk-libfido2.soSshdAuthPathPath to the sshd authentication helper on versions and platforms that support it. Normally managed by the package.
SshdAuthPath /usr/libexec/sshd-authSshdSessionPathPath to the sshd session helper on versions and platforms that support it. Normally managed by the package.
SshdSessionPath /usr/libexec/sshd-sessionStreamLocalBindMaskSet the octal file mode creation mask for a Unix-domain forwarding socket.
StreamLocalBindMask 0177StreamLocalBindUnlinkControl whether an existing Unix-domain socket is removed before creating a forwarding listener.
StreamLocalBindUnlink noUnusedConnectionTimeoutClose connections with no open channels after the specified time. Affected behavior and availability vary by version.
UnusedConnectionTimeout 5mX11DisplayOffsetSet the first display number available for X11 forwarding.
X11DisplayOffset 10X11UseLocalhostBind the X11 forwarding server to loopback when enabled; disabling it can expose the display more widely.
X11UseLocalhost yesXAuthLocationPath to the xauth program used for X11 forwarding where applicable.
XAuthLocation /usr/bin/xauthIPQoSSet IP quality-of-service markings for interactive and non-interactive sessions. Network devices may interpret or ignore these markings.
IPQoS lowdelay throughputMACsSelect message authentication code algorithms. Changing the defaults can affect security and client compatibility.
MACs hmac-sha2-256-etm@openssh.comSetEnvSet environment variables for child sessions. These values override variables accepted from clients or user environment files.
SetEnv LANG=en_US.UTF-8UseDNSControl reverse DNS lookup and verification for connecting clients. Enabling it may add delay if DNS is slow.
UseDNS noRecommended Starting Configuration
For a server with verified public-key login and no keyboard-interactive authentication requirement. TCP forwarding remains enabled for authenticated users; remote forwarded listeners bind to loopback.
PubkeyAuthentication yes
PasswordAuthentication no
KbdInteractiveAuthentication no
PermitRootLogin no
PermitEmptyPasswords no
AllowTcpForwarding yes
GatewayPorts noThis disables password and keyboard-interactive login, which may include PAM or one-time codes. Confirm another administrator account and its key work first. AllowTcpForwarding yes permits forwarding for authenticated users; restrict access where appropriate. Adapt the policy to your needs.
Keep your current session and a recovery method available. Merge these settings into the existing configuration rather than blindly appending: Include ordering, earlier values and Match blocks may override them. Run sshd -t, inspect sshd -T (and sshd -T -C for relevant Match conditions), then apply using your system’s service procedure and verify a second login before disconnecting.
Authoritative references
Reviewed October 27, 2026