Wednesday, July 7, 2021

How to keep your gnome-terminal from hanging in SSH connections

I've been having problems with my GNOME terminal hanging when on an extended SSH connection. Finally realized today there's probably a keepalive configuration somewhere.

There is.

Go into your ~/.ssh/config file and add this stanza under your Host config:

  ServerAliveInterval 240

(note the two spaces to make it a sub-property of Host)

If you want every SSH connection to stay alive, add the rule for every host

Host *
  ServerAliveInterval 240

FAQ

  1. Why isn't this the default?

    Really? You're using a Linux environment and you're asking why the default isn't "Don't just break?" 

    😉

2 comments:

  1. This smells like a case of an overly aggressive consumer-grade NAT device with a low timeout on TCP state, the sort of thing which works for HTTP but not most other protocols. You also sometimes see this with remote proxy gateways from certain cloud providers.

    TCP level keepalives can work, but having SSH do protocol-level keepalives can help. Meanwhile, not enabling this increases the chance that you can let your laptop sleep and then later open it up and the SSH connections could still work. A pleasant bonus for LAN hosts.

    ReplyDelete
    Replies
    1. While you're in there, if you work with SSH-based git repository hosting services, you probably want to look into ControlMaster auto with a 10s or so timeout for connection reuse. This can massively increase the odds of success for bulk-updates when behind certain WISPs which rate-limit SYN, etc. Also, hard-disable agent forwarding and only enable where explicitly needed, and view those cases with prejudicial suspicion as to why things were designed to require it.

      Delete