47

I use a Google Cloud VM and every once in a while I switch back to my terminal and see my ssh session has frozen. When I then try to reconnect

ssh -v  -i ~/.ssh/key  user@host.domain

It shows this:

OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/UserName/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 53: Applying options for *
debug1: Connecting to host.domain [123.456.123.456] port 22.
debug1: Connection established.
debug1: identity file /Users/UserName/.ssh/ke> type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/UserName/.ssh/key-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4

So it appears a connection is established, but nothing else happens and I need to restart the VM. What does this mean?

I should note that I can ping the host with no problem, so it's not frozen or anything.

oarfish
  • 896

2 Answers2

49
debug1: Local version string SSH-2.0-OpenSSH_7.4

When a client connects to an SSH server, the server starts the SSH protocol by sending a server version string in plain text to the client. With the OpenSSH ssh utility, the relevant debug lines look like this:

debug1: Local version string SSH-2.0-OpenSSH_7.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6

After the "local version" line, your client is waiting for the server to send its version string to the client. If the connection hangs here, it's because the client hasn't received the version string from the server.

Several things could cause this:

  1. The client has connected to something that's not an SSH server. For example, an HTTP server wouldn't send anything to the client, because the HTTP protocol expects the client to send the first data.
  2. The server is malfunctioning. For example the host might be overloaded, and the SSH server process isn't getting a chance to run.
  3. The server is hung somehow. It might be stuck doing a DNS query on the client's IP address, for example.
  4. A firewall or some other network device is interfering with the TCP connection.

In your case, you're connecting to port 22 so it's safe to assume you're connecting to an SSH server process. It seems likely you're suffering from #2 (the server is malfunctioning), but it's not possible to say exactly what is wrong beyond that. You would need to get into the server and figure out what was happening at the time which prevented it from processing SSH connections.

Kenster
  • 8,620
1

It's great explanation by @Kenster . I would like to add exact things that you can check.

My response is not cloud focused, but it could give some ideas in cloud too.

The line debug1: Remote protocol version 2.0, remote software version OpenSSH_7.6 is response from server which is missing.

So it could mean that server failed to deliver this packet to client over the network.

What you can use is tcpdump -i any host ip_address_here to trace it down if you are hosting SSH service (in my case it was git clone failing, I host SSH GIT service).

Additionally, you can simplify this to nc host.domain 22 and run this on different devices, even SSH server. It should usually print SSH server version when it works.

In my case, it worked on some machines, but not all.

~ server-1 $ nc example.com 22
SSH-2.0-APACHE-SSHD-2.X.X
^C

~ server-2 $ nc example.com 22 ^C ~ $

It was networking issue, related to configuration/filtering.

laimison
  • 228