:: TheOneAndTheOnly.com – Andrew Buckman ::

SFTP and SSH Timeout

Blogged in Apple,Web Design,Web Development by Andrew · Tuesday October 27, 2009

I bought a new router the other day, I was having some odd problems with my current one and thought it’d be nice to move to an 802.11n router.  I picked up a Netgear WNDR3700, my first foray into Netgear products.  Overall I’m pretty happy with the router except for one extremely annoying problem… it’s been timing out on my SFTP and SSH connections after just a 5-10 minutes.  I’m regularly working on a file directly off an SFTP connection and I often go more than 10 minutes between saving or interacting with the server.  Transmit gets kind of hung up with that happens and if you’re trigger happy on closing a window, you can end up losing your file altogether (not cool).  Suffice it to say, that happened yesterday and I had to quickly rewrite the code while I could remember the gist of it, and prompting me to get this annoyance straighted out.

I presume the problem I was having was related to the new router timing out the NAT tables more frequently than my old router and not doing anything with my requests after it timed out the connection.  Unfortunately, I could not find any settings in the router configuration to adjust this interval, however it was an extremely easy fix in Mac OS and it solved the problem for me with both SSH and Transmit.

The Fix
To fix the SFTP and SSH timeout problem in Mac OS, go to your home folder and look for a folder with the name .ssh (note it will be hidden in Finder, I just used Terminal).  Inside the folder you probably already have a known_hosts file, and you may or may not have a config file, I did not.  Create or modify the config file, including the following code, taking care to make certain you indent the second line:
Host *
       ServerAliveInterval 240

This should tell your computer to keep the ssh connection alive every 240 seconds (4 minutes).  You can adjust this number as you see fit, as long as it’s lower than your router’s NAT timeout, it will resolve the problem.

NOTE: You will have to do this on every computer you’re using with the router.  I was hoping to fix it on the router itself and not have to deal with it, but this is certainly better than nothing.

Leave a Reply

©2010 Andrew Buckman
35 queries. 0.262 seconds.
Powered by Wordpress
theme based on desert by evil.bert