This guide explains how to use the MaxStartups and MaxSessions parameters to limit client connections to the OpenSSH Server service.
These settings help you troubleshoot connection issues and manage unauthenticated and authenticated SSH sessions, especially in high-load environments.
Symptoms
You can use MaxStartups and MaxSessions to address the following types of symptoms.
-
Symptom 1: Clients can't connect to the OpenSSH Server service and establish sessions. Additionally, you might receive the following error messages:
- Connection reset by peer
- Exceeded MaxStartups
- Negotiation failed
-
Symptom 2: In an environment that supports session multiplexing (multiple sessions per connection), clients connect and authenticate. However, the server drops the connection.
Cause
Symptom 1 indicates that too many client applications are connecting to the OpenSSH Server service at the same time.
Symptom 2 is limited to multiplexing environments. It indicates that the OpenSSH Server service can't support the number of sessions per connection that the clients are using. This symptom can occur after you configureMaxStartups.
How to use the parameters
MaxStartupsand MaxSessions are parameters in the sshd_config file. The following sections explain how they function.
MaxStartups
The MaxStartups parameter defines how many concurrent unauthenticated connections the OpenSSH Server service can manage. This setting is especially useful on servers that support multiple parallel SSH connections, including jump hosts and provisioning servers (such as servers that use Ansible). It's also useful in high-load environments or during brute-force attacks.
The value is a set of three integers that are separated by colons, in the format Start:Rate:Full. The integers represent the following values:
- Start: The number of unauthenticated connections that the OpenSSH Server service supports before it starts dropping connections.
- Rate: Probability that the OpenSSH Server service drops a connection. As long as the number of concurrent sessions is below the
Startvalue, the service ignoresRate. However, when the number of concurrent connections surpassesStart, each additional connection has aRatepercent probability of being dropped. - Full: When the number of concurrent connections surpasses
Full, the service drops all additional connections.
For example, consider a system that's using the configuration, MaxStartups 20:40:60. The OpenSSH Server service manages connections as follows:
- The service maintains the first 20 concurrent unauthenticated connections.
- Starting at the 21st connection attempt, there's a 40 percent probability that the server drops the new connection attempt.
- After the service reaches 60 concurrent unauthenticated connections, the server rejects all further connection attempts.
MaxSessions
The MaxSessions parameter defines how many open shell, login, or subsystem (for example, sftp) sessions that the OpenSSH Server service permits for each network connection. Setting MaxSessions to 1 effectively disables session multiplexing. Setting it to 0 prevents all shell, login, and subsystem sessions, but allows port forwarding. The default value is 10.
How to set the connection parameters
To modify the parameters for the Windows OpenSSH Server service, modify the sshd_config file, and then restart the OpenSSH Server service. To do this, follow these steps:
-
Using an Administrator-level account, open a text editor, and then open %ProgramData%\ssh\sshd_config. The default text for these settings should resemble the following excerpt:
#MaxStartups 10#MaxSessions 10[!NOTE]
MaxSessionstypically appears within the# Authenticationsection of the file.MaxStartupstypically appears in a list of general options later in the file. -
To enable
MaxStartuporMaxSessionsand to set values, edit the text to resemble the following excerpt:MaxStartups 20:40:60MaxSessions 15[!NOTE]
In this command,20:40:60and15are example values. Use values that are appropriate for your environment. -
Save and close the sshd_config file.
-
To verify the configuration, open a Windows PowerShell Command Prompt window, and then run the following command:
sshd -t -
To restart the OpenSSH Server service, open a Windows Command Prompt window, and then run the following command:
NET STOP "OpenSSH SSH Server" && NET START "OpenSSH SSH Server"
After the service restarts, it uses the new parameter values.
More information
- Windows configurations in sshd_config in "OpenSSH Server configuration for Windows Server and Windows"
- sshd_config(5) - Linux manual page
- sshd_config - OpenSSH daemon configuration file
Third-party information disclaimer
The third-party products that this article discusses are manufactured by companies that are independent of Microsoft. Microsoft makes no warranty, implied or otherwise, about the performance or reliability of these products.
Source: Microsoft Learn / IT Pro troubleshooting by Microsoft and contributors. Documentation licensed CC BY 4.0. Code samples are covered by the MIT License. Converted from Markdown, with links normalized and embedded media omitted.
