A minor annoyance: SSH Keeps Freezing

2 minute read 2014-11-10 Ashkan Kiani -

TL;DR.

echo 'Host *
  ServerAliveInterval 240' >> ~/.ssh/config && chmod 600 ~/.ssh/config

Additionally, <CR>~. terminates the session.

Story

I have a server that runs Ubuntu, and after a little while of inactivity, the server would stop responding to commands. I have this bad habit sometimes of ignoring a problem and accepting a half-solution (in this case I would just go back to the session every so often and type ls because that's always the first thing I type in a terminal, regardless of whether I need it or not), but seeing as how I'm an engineer who loves to solve problems, eventually I wisen up and go for it.

So today I did a little bit of Google-fu and found a few Superuser/StackOverflow questions that had the solution (of course they did). First I found this, which was useful for learning that there is a way to terminate a frozen session (assuming that your SSH escape key is still the default, which if it isn't, then you probably already know this anyway).

So to terminate a frozen session, type <CR>~. using Vim syntax where <CR> is just Enter. I found that works, but it's not quite what I wanted.

So I found this which is basically everything I wanted, and you can tell your client to send a heartbeat for a specific remote or all remotes, which is what I did by adding the following to my ~/.ssh/config:

Host *
  ServerAliveInterval 240

And then I set permissions to chmod 600 ~/.ssh/config to allow read by all.

Misc.

Did you know you can use lazy references in markdown? [this link][1] sets the link, and [1]: http://google.com defines the link. The definition is invisible and lets you have a named reference. Cool.

References

[1] [2] [3]


published in programming and tagged mac , ssh and devops