Strovent SystemsSign in
Reference

ssh -v hangs at "expecting SSH2_MSG_KEX_ECDH_REPLY" or after "Connection established"

Where ssh -v stops tells you what is stuck. After "Connection established" the server banner never came; at KEX_ECDH_REPLY large packets are being lost.

ssh -v prints each step of the connection. When it stops and waits, the last line tells you which step is stuck.

Stops right after "Connection established"

debug1: Connecting to host.example.com port 22.
debug1: Connection established.

The TCP connection is open, but the server has not sent its SSH-2.0-… identification line yet. That is the banner exchange: something accepted the connection but has not answered like an SSH server. If it then fails with "Connection timed out during banner exchange" or "Connection closed", see SSH banner exchange errors, "Connection closed" and "timed out during banner exchange".

Stops at "expecting SSH2_MSG_KEX_ECDH_REPLY"

debug1: kex: algorithm: curve25519-sha256
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY

Here the banners were exchanged and the client has sent its key exchange packet. It is waiting for the server's reply. IBM and Red Hat both describe this hang as an MTU problem: a link on the path has a smaller MTU than the hosts, and IBM's note explains that key exchange packets can be larger than that, so they are dropped. The smaller packets before them got through, which is why the connection gets this far.

Red Hat's article describes the same symptom ending in "Connection closed by … port 22" after a wait, with the key exchange packet being retransmitted.

Check

On Linux, test the path with pings that are not allowed to be fragmented:

ping -M do -s 1472 host.example.com

1472 bytes of data plus 28 bytes of headers makes a 1500-byte packet. If this fails but smaller sizes work, the path cannot carry full-size packets. ip link show shows each interface's MTU.

IBM's note also suggests a quick test: try a different key exchange with ssh -o KexAlgorithms=ecdh-sha2-nistp521 user@host. If that connects, the packet size is the problem, not the server.

Fix

Make the MTU the same on the client, the server and the devices between them, as both articles recommend. Changing the key exchange is a test, not a fix.

Sources

Spotted a mistake? Email [email protected].