How to keep an SSH session alive

* This is a Has it ever happened to you… kind of post.

Imagine you’re logged in to a server doing some magical stuff. Then you go grab a coffee and when you come back… you’re logged out from the server. Yes, it sucks. You have to SSH in again and cd into the same dir you were before, etc. Ain’t nobody go time for that.

What if I told you that you can keep an SSH session alive? 🚀
All you have to do is edit your ~/.ssh/config file and add the following:

Host *
ServerAliveInterval 60

You can define a specific host, and choose the interval. Most servers with which I have this issue have a rather low timeout, so I’ve chosen to send the keep alive signal every 60 seconds.

And baam, you’ve freed yourself from this annoyance.

rockymonkey555 over stackoverflow.com recommends to also chmod 600 ~/.ssh/config, “because the config file must not be world-readable”.

I hope this is as useful to you as it’s been for me.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Comments (

)

  1. Lucas Nuñez

    Happened every time… :’)