I'm trying to figure out why open SSH connections are disconnected

Hello,

Long time customer, first time caller.

I'm having trouble keeping SSH connections alive when connected to my Linode. I went through a few things with Support (described below), but those things haven't resolved the problem and I'm turning to the community for additional help.

If I reboot my Linode, I can SSH into it, again, for what seems like a limited length of time (perhaps 10 - 30 minutes or so?). Then, unexpectedly, the session ends and my console says "port 22 closed" and something about a "broken pipe".

Here's what Support and I have tried:

  • We ran mtr from my laptop to my Linode and all was deemed well.

  • We ran mtr from my Linode back to my laptop — same result: all was deemed well.

  • I added the following to my Linode's /etc/ssh/sshd_config file:

–- ClientAliveInterval 20

--- ClientAliveCountMax 5

  • I added the following to my laptop's ~/.ssh/config:

--- Host *

--- TCPKeepAlive yes

--- ServerAliveInterval 120

I'm running macOS Sierra on my laptop, and this problem happens at home and at the office … so I think we can rule-out local network specific things? I'm not really good at this stuff, in general; what you see above is about as skilled as I get — any ideas what else I might try to diagnose and/or resolve this issue?

Thank you!

5 Replies

Quick follow up: If I try to connect again, immediately, it refuses … however, if I wait a bit longer (10 - 30 minutes, not exactly sure), it allows me to SSH back in.

With TCPKeepAlive set to yes, you have the side-effect of cutting your own connection when routing between the two machines is temporarily blocked (like when a router is rebooted, etc). Thus when this is enabled, it causes ssh to drop more often than usual. This method sends keepalive messages via TCP unencrypted.

My suggestion, is to remove the sshd_config lines you added (ClientAlive*) they are not needed. What I suggest, is to lower your ServerAliveInterval in your ~/.ssh/config to something less than or equal to 30, try with an empty config file that only has this line:

ServerAliveInterval 30

Usually that is all it takes to force ssh connections to live forever, until closed by hand, if 30 isn't enough then keep lowering the value down to 15. Make sure to restart your sshd after you make the changs.

I've had a connection open (and, entirely idle/unused) for a few hours now — I think you did it! So many many thanks, IfThenElse!

Nice, I'm glad it worked :)

I had this issue for months now and this seems to fix it as well.

My error message shows:

packet_write_wait: Connection to xxx.xxx.xxx.xxx port 22: Broken pipe

Thanks!

Reply

Please enter an answer
Tips:

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (https://www.google.com)

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct