Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

From outside of my house, whenever I login to my Ubuntu server using SSH, it takes about 6 seconds for me to get the prompt for password, however when I login to my web hosting server it takes about 1 second. What can I do to speed this up?

$ cat /etc/lsb-release
$ ssh -v
OpenSSH_4.7p1 Debian-8ubuntu1.2, OpenSSL 0.9.8g 19 Oct 2007
$ cat /proc/cpuinfo
model name      : Dual-Core AMD Opteron(tm) Processor 1210
cpu MHz         : 1000.000
cache size      : 1024 KB
$ cat /proc/meminfo
MemTotal:      2074528 kB
share|improve this question
up vote 35 down vote accepted

The number one reason I've seen for this is a configuration option in SSHD UseDNS this option (enabled by default) causes the server to perform DNS resolution on the incoming requests. A time consuming operation. I've seen logins go from one minute plus waiting for password prompt to under a few seconds. If you edit /etc/ssh/sshd_config on the server and add (if it's not there) at the bottom UseDNS no then restart the SSH daemon with service ssh restart you should see an improvement next time you connect.

share|improve this answer
Better to fix your DNS configuration. – Thorbjørn Ravn Andersen Aug 16 '10 at 15:41
This worked out great!! Thanks! The login time went from 20-30 secs to less than 5 secs :) – AntonioCS Aug 16 '10 at 20:56
What is the benefit of having UseDNS enabled? – ændrük Sep 7 '10 at 15:02
Be aware! when you set the directive UserDNS after a Match directive you'll get an error: is not allowed within a Match block if you restart the sshd you'll not be able to ssh into your server. I did this mistake and I got locked out of my server. Always remember do not add any directive at the bottom of sshd_config if you have Match directive in it. – Adriano Rosa Jan 26 '15 at 19:44

For me, the reason number 2 (after the server-side UseDNS option) for long SSH session logins are client side attempts to connect using IPv6 (which, obviously, isn't set up correctly on my network - or almost any other network, for that matter).

See HOWTO: Speed up SSH login on Ubuntu forums.

The "solution" is to enable IPv4 only:

1) either for the given SSH client invocation:

ssh -4 login@hostname

2) or globally in ssh client conffiguration in /etc/ssh/ssh_config:

Host *
   AddressFamily inet

Of course, it would be more correct to set up IPv6 on your network properly, but who has the time for that :)

share|improve this answer

As you are using a rather old Ubuntu version, it might well be this bug:

Restarting dbus (/etc/init.d/dbus restart) might help.

share|improve this answer
I have a 10.04 box upgraded from 9.04 and 9.10. Restarting dbus reduced time ssh remoteServer date from 8s to 0.5s. – djeikyb May 4 '11 at 10:38

Try adding the next option with your ssh command:

-o "PreferredAuthentications=password"

(this prevents ssh from negotiating any other authentication method, and speeds up the password promtp!)

share|improve this answer
Why use passwords at all? Why not keys? – TJ Ellis Dec 17 '10 at 17:50
Easy: because you may not be allow to use keys! (sshd not configured to use them, bad user file permissions, etc.9 – perseo22 Jan 14 '11 at 12:37

Additionally, type this on the remote machine (as the user you would log in as) to suppress any MOTD messages:

touch ~/.hushlogin

Doesn't make as much a difference as turning off UseDNS but it might help on slower connections.

share|improve this answer
-1: The MOTD is only displayed after a successful login. This will not cause the password prompt to appear any faster. – Asa Ayers Aug 16 '10 at 16:26
True, but still a useful comment. – sebastian_k Sep 2 '11 at 18:49

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.