Getting Rid of SSH or SFTP Delay
This is for my future reference and anyone else who stumbles accross the annoying 5-10sec SSH/SFTP delay when connecting to remote hosts.
The delay is most likely caused by the host trying to reverse DNS the client’s ip address. You can make sure this is the reason by connecting to the remote host with the -vv parameter (this is all assuming debian/ubuntu type distros):
ssh -vv user@example.com
If the debug output pauses before a message like:
debug1: Authentications that can continue: publickey,password
Then most likely reverse lookup is the problem. Fortunately, the solution is simple – on your remote host, edit the ssh config file:
sudo nano /etc/ssh/ssh_config
Add the following line if it doesn’t already exist:
UseDNS no
Then restart ssh:
sudo /etc/init.d/ssh restart
Voila! You should not experience a delay anymore when connecting via SSH or SFTP, etc.














gishdog 3:32 pm on October 29, 2008 Permalink
Nice!
aaronasjones 8:22 am on March 14, 2009 Permalink
Thank you for sharing this information.
Reverse Access Livedoor
v3 3:12 pm on March 15, 2009 Permalink
Thanks, did the job for me!
v3 10:12 pm on March 15, 2009 Permalink
Thanks, did the job for me!
Iox 12:11 pm on May 24, 2009 Permalink
Thank you!
Michael Ben-Nes 10:47 am on August 13, 2009 Permalink
In my case I found another solution.
When debuging the problem my ssh returned:
debug1: Unspecified GSS failure. Minor code may provide more information
It was fixed by setting:
GSSAPIAuthentication no
myriapod 12:19 pm on October 2, 2009 Permalink
shouldn't it be sshd_config?
Juan 2:19 pm on January 6, 2011 Permalink
Thank you. This is specially usefull if you get a “ERROR – Lookup Failed” for the reverse DNS for the IP's you get from your ISP
Jo Liss 11:42 pm on March 6, 2011 Permalink
Yup, definitely — UseDNS belongs in sshd_config, not ssh_config.
Matt 3:40 pm on March 22, 2012 Permalink
Thanks for this. Really useful for me, when I use svn+ssh. It’s as fast as it should be, now!
Noah Lively 4:18 pm on April 13, 2012 Permalink
I had to add this line to /etc/ssh/sshd_config, rather than /etc/ssh/ssh_config