Friday, February 23, 2007

 

Prevent Timeouts in SSH

Many routers timeout the connection after some period of inactivity. For users of ssh, this can a big nuisance. In presence of such routers a ssh connection with no activity (for a few minutes) will disconnect automatically. The workaround is that the server and client keep talking to each other even when the user is not typing (or viewing) anything. This can be achived using one of the two ways:

Server Side

Add the following two lines to /etc/ssh/sshd_config. This will make the server poll for client every 30 seconds. If the client fails to respond for 4 times (i.e., 2 mins), the server will close the connection. Note that this applies to version 2 of OpenSSH only.

ClientAliveInterval 30
ClientAliveCountMax 4

Client Side

Add the following two lines to /etc/ssh/ssh_config (or $HOME/.ssh/config if you don't have root access). his will make the client poll for server every 30 seconds. If the servers fails to respond for 4 times (i.e., 2 mins), the client will close the connection. Note that this also applies to version 2 of OpenSSH only.

ServerAliveInterval 30
ServerAliveCountMax 4

Labels: ,


Comments:
Thanks for the tip. Connection to my gateway used to timeout after every 4-5 minutes of inactivity.
 
This comment has been removed by a blog administrator.
 
Thanks, this worked for me against Virgin Media's nasty traffic interference policy :)
 
Thanks! :) exactly what I needed... and you're about the first Google hit on this query :)
 
Thank you. Useful.
 
Great tip! Thanks :)
 
Post a Comment

Links to this post:

Create a Link



<< Home

This page is powered by Blogger. Isn't yours?