SSH banner exchange errors, "Connection closed" and "timed out during banner exchange"
Why SSH fails before login with "kex_exchange_identification: Connection closed", "timed out during banner exchange" or an invalid identification string.
Every SSH connection starts with a short exchange. After the TCP connection opens, each side sends one line naming itself, for example SSH-2.0-OpenSSH_9.6. RFC 4253 calls this the protocol version exchange, and OpenSSH calls it the banner exchange. Key exchange begins right after it.
If something goes wrong here, the error is about the connection, not your key, password or algorithms. These are the common forms.
"Connection closed by remote host" or "Connection closed by host port 22"
Older OpenSSH versions print kex_exchange_identification: Connection closed by remote host. Newer ones print Connection closed by 192.0.2.10 port 22. In both, the host closed the TCP connection before it sent its identification line.
A related form is kex_exchange_identification: read: Connection reset by peer. Here the host reset the connection while the client was waiting for that line.
The connection reached something and was then cut off. On the host, the documented ways an SSH server does this are:
MaxStartups. It is the maximum number of connections that have not yet logged in. "Additional connections will be dropped until authentication succeeds or theLoginGraceTimeexpires for a connection." The default is10:30:100, which starts dropping connections at random once 10 are waiting, and drops all at 100. A host that is being scanned or hit by many connections at once can reach this limit.PerSourcePenalties. Enabled by default in recent OpenSSH, it refuses new connections from an address, and others in the same network block, for a period after certain conduct. One example is disconnecting after failed authentication attempts. A penalty does not affect connections already open. To read the server log lines these clients leave, see sshd log "Received disconnect ... 11: Bye Bye" with preauth.- A wrapper in front of sshd. RFC 4253 notes that a server may send other lines before the identification line, and says the main use is to let TCP wrappers show an error message before they disconnect. If you see such text, read it.
Other possibilities, such as a firewall resetting the connection or a service on that port which is not SSH, are not specific to this message. For all of them, the administrator needs the time of the attempt and your public IP address, and can check the SSH server's log.
"Connection timed out during banner exchange"
The TCP connection opened, but the host's identification line did not arrive in time. Your client's ConnectTimeout covers this: it applies to "establishing the connection and to performing the initial SSH protocol handshake and key exchange". The line that follows is Connection to 192.0.2.10 port 22 timed out.
Things to try:
- Retry. If it is intermittent, the host may be busy or slow to answer.
- Raise the time-out with
ssh -o ConnectTimeout=30 user@host, or setConnectTimeoutfor that host in~/.ssh/config, if the default is too short for a slow link. - Check you are using the right port and host. A service on that port that accepts a connection but does not speak SSH can leave the client waiting.
- Run
ssh -vand see how far it got.
"Invalid SSH identification string" or "No SSH identification string received"
The other end answered, but not with an SSH identification line. A server may send other text first, but OpenSSH gives up if it sees no SSH- line within its limit. This is what you see when the port belongs to another service, such as a web server or a proxy.
To test the port by hand, see Telnet to port 22: what the SSH-2.0 banner means.
Related
- SSH: how it works
- SSH problems
- SSH "no matching key exchange method" and "no matching host key type" errors
- Connection abort, reset and timed-out errors
- SSH error messages, what each one means
- Telnet to port 22: what the SSH-2.0 banner means
- sshd log "Received disconnect ... 11: Bye Bye" with preauth
- ssh -v hangs at "expecting SSH2_MSG_KEX_ECDH_REPLY" or after "Connection established"