Thursday, May 01, 2008

Fix slow ssh response

When logging into an ssh server you may experience a long delay after authentication, and before you get the prompt. This will happen with most sshd servers on a home network or on a new network while it is being set up.

The reason is that sshd tries to do a reverse lookup on the connecting IP, which takes a while to time out.

To speed up the initial response of ssh, the solution is to prevent these reverse lookups, at least until the network has a working DNS which can resolve the connecting IPs to names. To do this, set "UseDNS no" in your sshd_config file and force sshd to re-read it's configuration.
sudo -s # if you are not root, like on Ubuntu or Mac

# or
# or on a Mac

perl -i.bak -pe 's/^\s*#?UseDNS\s+.*/UseDNS no/i' $file
grep -qi 'UseDNS no' $file || echo UseDNS no >> $file
# on Linux:
kill -HUP `cat /var/run/`
(the last kill line to force sshd re-read it's config file doesn't work on Mac)
While searching for this solution, I came across other configuration settings. They didn't apply to my case, but if you still have problems, you may want to set "GSSAPIKeyExchange no" in your client configuration file which is usually in /etc/ssh_config (ssh_ , not sshd_ !). Or look into IPv6 problems.

Now I have to find an equivalent solution for rsync.

Labels: , , , , ,


Anonymous Anonymous said...

Thanks for pointing me out to this. Such slow response behaviour doesn't bother me actually that much, but from time to time I've been wondering why some servers response right away while logging to them with SSH-client.

By default reverse DNS lookups are enabled even if "UseDNS yes" is not set for sshd_config file configuration.

Anyway, for me setting "UseDNS no" did the trick.

21 August, 2008 16:01  
Anonymous Anonymous said...

Thanks! Worked like a champ!

05 January, 2010 02:27  
Anonymous tommy said...

works! thanks

09 October, 2010 05:11  
Anonymous Anonymous said...

This has been bugging me for over a year, finally solved, thank you!

07 January, 2011 10:21  
Anonymous Anonymous said...

Me too, this slow ssh had bugged me for such a long time.. awesome tip !

18 November, 2011 18:46  

Post a Comment

<< Home