Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=8.04
DISTRIB_CODENAME=hardy
DISTRIB_DESCRIPTION="Ubuntu 8.04.1"
$ 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
add comment

5 Answers 5

up vote 22 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
4  
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
3  
What is the benefit of having UseDNS enabled? –  ændrük Sep 7 '10 at 15:02
add comment

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
add comment

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
2  
Why use passwords at all? Why not keys? –  TJ Ellis Dec 17 '10 at 17:50
1  
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
add comment

As you are using a rather old Ubuntu version, it might well be this bug: https://bugs.launchpad.net/ubuntu/+source/openssh/+bug/300151

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
add comment

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  
-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
1  
True, but still a useful comment. –  sebastian_k Sep 2 '11 at 18:49
add comment

Your Answer

 
discard

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.