Keep Your SSH Connection Open

Do you get annoyed when you have a SSH session open, visit your browser for a while, and then return only to find you were disconnected? Most home NAT routers are the cause of this. If your router doesn't offer an option to not shut off idle connections, you are probably better off by setting a keep-alive setting.

To do this, just open /etc/ssh/ssh_config on your home (client) computer. Add the following line:

ServerAliveInterval 180

There you have it! Just remember now, if you leave SSH open accidentally, anyone else can get on it. Remember to close your session when finished.

Avatar for jacob Jacob Peddicord - http://jacob.peddicord.net/

Jacob is a web developer, student, and programmer from Ohio. He is a staff member at the Ubuntu Forums and is most likely a fanboy of the distribution. He loves to write in code and words, play video games, and rant about topics most would have abandoned long ago. Jacob uses GNOME and is never seen running stable software, much to the demise of his laptop.

Home » Articles »

Discussion: Keep Your SSH Connection Open

  1. Brian Pence (guest)

    # Posted on 19 February 2008 at 11:15 PM

    If you're using AbsoluteTelnet (for Windows), you can do this from the Options->Properties->Connection page. There is an option there to enable keepalives and you can specify the duration between them.

    Regards,

    Brian Pence



  2. Lou Palladino (guest)

    # Posted on 20 February 2008 at 05:11 PM

    Make sure your SSH client supports SSH keepalives, or this won't work either. You can set the TCP keepidle option to the value and that will fix it no matter what service (telnet/SSH) or client you are using. Procedures differ depending on the OS flavor.



  3. # Posted on 20 February 2008 at 07:45 PM

    [...] Tack för tipset FOSSwire! [...]



  4. # Posted on 20 February 2008 at 11:59 PM

    <strong>Story added...</strong>

    This story has been submitted to fsdaily.com! If you think this story should be read by the free software community, come vote it up and discuss it here:

    http://www.fsdaily.com/HighEnd/Keep_Your_SSH_Connection_Open...



  5. nick (guest)

    # Posted on 21 February 2008 at 09:19 AM

    Why dont you just use a watch command with something simple like ls. for example the command "watch ls -la" and it will do it every two seconds or whatever time you designate. or if you want to make sure there isnt any system load do something like "watch echo "hello";"

    just a suggestion



  6. # Posted on 22 February 2008 at 05:37 PM

    [...] are just that&mdash;open to any nefarious passer-by, so use session-closing caution when needed. Keep Your SSH Connection Open [...]



  7. # Posted on 23 February 2008 at 04:18 PM

    [...] open are just that—open to any nefarious passer-by, so use session-closing caution when needed. Keep Your SSH Connection Open [FOSSwire] no comments yet. Top 10 Smart and Lazy Ways to Save Your Workday [Lifehacker Top [...]



  8. # Posted on 07 April 2008 at 02:55 AM

    [...] are just that&mdash;open to any nefarious passer-by, so use session-closing caution when needed. Keep Your SSH Connection Open [FOSSwire] Bookmark this article! [...]



  9. Anıl (guest)

    # Posted on 04 July 2008 at 08:09 AM

    Hi, is there any way to make a process continue even after ssh connection aborts?



  10. Peter (guest)

    # Posted on 04 July 2008 at 06:10 PM

    @Anıl - if you schedule it with at or <a href="http://fosswire.com/2007/03/13/scheduling-tasks-with-cron/" rel="nofollow">cron</a> for a time shortly in the future, you can then disconnect, but the command will still be run in the background. You should get mailed any output.



  11. jbroome (guest)

    # Posted on 07 July 2008 at 05:30 AM

    @Anil

    Run your command in a screen session.



  12. # Posted on 16 January 2009 at 02:41 PM

    [...] article this morning about keeping SSH connections open in Linux (which was just a re-posting of an article on [...]



  13. Brian Pence (guest)

    # Posted on 27 January 2009 at 09:13 PM

    &gt;&gt; &gt;&gt; Hi, is there any way to make a process continue even after ssh connection aborts &gt;&gt;

    Yes, check out the 'nohup' command. Use it like this:

    nohup mycommand.sh

    It will keep running, even if your shell closes (true for telnet, ssh, dialup, whatever)

    Even better, nohup it into the background so you don't tie up the shell:

    nohup mycommand.sh &amp;

    Brian



  14. Brian Pence (guest)

    # Posted on 27 January 2009 at 09:13 PM

    BTW, with 'nohup', stderr and stdout are redirected to a file 'nohup.out'.



Home » Articles » Keep Your SSH Connection Open

Sign In