Search code examples
sshconnection-timeouttcp-keepalive

work-around for idle ssh sessions dropped because of "packet_write_wait: Connection to 192.168.xx.yyy port 22: Broken pipe"


here's the scenario: you ssh into a remote linux host, leave the terminal idle for a while and come back to find the connection has dropped.

You've read the suggestions about setting keep-alive on the connection, and tried it, and it still fails.

You maybe even know about screen and/or tmux but still would rather not have to reconnect so often.

Is there any way of accomplishing this?


Solution

  • Here are two workarounds which may be acceptable/helpful to some:

    1. run emacs with the time display in the mode line. You can run this in place of screen/tmux and use the built-in terminal mode which is surprisingly functional, and your connections will not drop
    2. use something like the following when you leave your terminal

      alias keep_alive='while true; do ( sleep 60 ; date ) ; done'
      keep_alive
      

      then ctrl-c when you come back. It sleeps nearly all the time and in my experience printing the date every sixty seconds prevents the connection from timing out.