Subscribe to How-To Geek

Recommended: Click Here to Run a Free Scan for Common PC Errors   [Sponsored Link]

Keep Your Linux SSH Session From Disconnecting

I'm the type of geek that has an SSH client open at all times, connected to my most frequently used servers so that I have instant access for monitoring and anything else. As such, it irritates me greatly when I get disconnected, so I'm sharing a few methods for keeping your session alive.

You can configure the ssh client to automatically send a protocol no-op code code every number of seconds so that the server won't disconnect you. This is setting is sometimes referred to as Keep-Alive or Stop-Disconnecting-So-Much in other clients.

Global Configuration

Add the following line to the /etc/ssh/ssh_config file:

ServerAliveInterval 60

The number is the amount of seconds before the server with send the no-op code.

Current User Configuration

Add the following lines to the ~/.ssh/config file (create if it doesn't exist)

Host *
  ServerAliveInterval 60

Make sure you indent the second line with a space.

Per-Host Configuration

If you only want to enable keep alive for a single server, you can add that into the ~/.ssh/config file with the following syntax:

Host *hostname.com
   ServerAliveInterval 60

Works quite well, hope it helps somebody else out there.

The Geek is the founder of How-To Geek and a geek enthusiast. When he's not coming up with great how-to articles, he's probably writing at his personal blog. This article was written on 08/16/07 and tagged with: Linux

Comments (4)

  1. Micha

    Thanks a lot!

    That'll save my life!
    OK, I wouldn't die if i didn't know this, but it shuold make life easier. I hate being disconnected…

  2. Chuck

    That's a great tip. Another idea (one you can use in tandem with the above) is to use the "screen" program. Then, if you are somehow disconnected you can just re-atach the screen and all your stuff is there just as you left it.

  3. Dan

    Already knew this, but it popped up on my iGoogle page as I have your feed on there, great tip and excellent explination, K.I.S.S :D (Keep it simple Stupid)

    I'll be pointing some of my customers to this blog entry :P

  4. oOJINxOo

    ty soooo much ^_^


Leave a Comment




Leave your friendly comment here. If you have a computer help question, leave it on the forums instead.

Note: Your comment may not show up immediately on the site.

Copyright © 2006-2008 HowToGeek.com. All Rights Reserved.