23

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

5 Answers 5

38

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.

4
  • 6
    Better to fix your DNS configuration. Aug 16, 2010 at 15:41
  • This worked out great!! Thanks! The login time went from 20-30 secs to less than 5 secs :)
    – AntonioCS
    Aug 16, 2010 at 20:56
  • 3
    What is the benefit of having UseDNS enabled?
    – ændrük
    Sep 7, 2010 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. Jan 26, 2015 at 19:44
6

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 :)

3

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!)

2
  • 2
    Why use passwords at all? Why not keys?
    – TJ Ellis
    Dec 17, 2010 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, 2011 at 12:37
2

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.

2
  • 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, 2010 at 16:26
  • 2
    True, but still a useful comment.
    – sk29910
    Sep 2, 2011 at 18:49
2

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.

1
  • 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, 2011 at 10:38

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .