Getting Rid of SSH or SFTP Delay

October 23, 2008

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

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.