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.

When I try to connect ssh it takes too long (almost 2 minutes) to appear password prompt.

Why does this happens?

share|improve this question
1  
The answer of Gilles should be the answer as explained in the comments, really. –  gertvdijk Jan 25 '13 at 17:47

5 Answers 5

up vote 26 down vote accepted

There are several things that can go wrong. Add -vvv to make ssh print a detailed trace of what it's doing, and see where it's pausing.

The problem could be on the client or on the server.

A common problem on the server is if you're connecting from a client for which reverse DNS lookups time out. (A “reverse DNS lookup” means getting back from the client machine's IP address to a host name. It isn't really useful for security, only slightly helpful to diagnose breakin attempts from log entries, but the default configuration does it anyway.) To turn off reverse DNS lookups, add UseDNS no to /etc/ssh/sshd_config (you need to be root on the server).

Another thing that can go wrong is GSSAPI authentication timing out. If you don't know what that is, you're probably not relying on it; you can turn it off by adding the line GSSAPIAuthentication no to /etc/ssh/ssh_config or ~/.ssh/config (that's on the client side).

share|improve this answer
1  
For me it was the GSSAPIAuthentication problem. Thank you. –  Raja Varma Oct 18 '13 at 10:18
    
This has been a problem for me when I ssh into a server in my own apartment. Some combination of DynDNS and port fowarding must've made me hit the DNS timeout issue you described. Thank you! –  Jack O'Connor Dec 23 '13 at 10:44
1  
GSSAPI was my problem, thanks. –  jco Dec 23 '13 at 11:28
    
I also had to disable GSSAPI, it's enabled by default on Raspberry PI radpbian. –  Tomáš Zato Jan 3 at 14:36
    
+1 for GSSAPIAuthentication no ! Vive Gilles ! –  Slyx Feb 17 at 15:55

It is something that comes wrong from Ubuntu's installation.

To fix it you have to change this line in /etc/nsswitch.conf:

hosts:          files mdns4_minimal [NOTFOUND=return] dns mdns4

And change it for this one:

hosts:          files dns
share|improve this answer
3  
Ubuntu's configuration isn't wrong. In some cases (home networks with no central DNS servers), it's the right thing. In others (networks where mDNS requests time out), it's bad. –  Gilles Jan 22 '13 at 21:16
    
the [NOTFOUND=return] should not be there. –  Neuquino Jan 25 '13 at 17:47
4  
@Neuquino It should be there. It's there for a reason you don't understand, apparently. Fiddling with your nsswitch.conf like this is asking for trouble and not providing a general solution to slow SSH. –  gertvdijk Jan 25 '13 at 17:47

Let time the login process and see how long it will take:

[root@gislab00207 ~]# time ssh root@ISSLABNTL01
root@isslabntl01's password:
Last login: Fri Oct  4 07:55:03 2013 from 3.60.40.232

[root@ISSLABNTL01 ~]# exit
logout
Connection to ISSLABNTL01 closed.

real    0m45.192s
user    0m0.003s
sys     0m0.005s

You have new mail in /var/spool/mail/root
[root@gislab00207 ~]#

See above it took about 45 seconds to login -------- VERY SLOW

Once You login as root edit sshd_config file and change the UseDNS entry as below. Here I am using sed instead of editing the file.

[root@ISSLABNTL01 ~]# grep -i dns /etc/ssh/sshd_config
#UseDNS yes

[root@ISSLABNTL01 ~]# sed -i 's/#UseDNS yes/UseDNS no/g' /etc/ssh/sshd_config
[root@ISSLABNTL01 ~]# grep -i dns /etc/ssh/sshd_config
UseDNS no

[root@ISSLABNTL01 ~]# service sshd restart
Stopping sshd:                                             [  OK  ]
Starting sshd:                                             [  OK  ]
[root@ISSLABNTL01 ~]# exit

Let us time the login process and see now how long it will takes.

[root@gislab00207 ~]# time ssh root@ISSLABNTL01
root@isslabntl01's password:
Last login: Fri Oct  4 07:55:03 2013 from 3.60.40.232

[root@ISSLABNTL01 ~]# exit
logout

Connection to ISSLABNTL01 closed.

real    0m6.192s
user    0m0.003s
sys     0m0.005s

You have new mail in /var/spool/mail/root
[root@gislab00207 ~]#

See it took now 6 seconds, the time for me to type the password.

share|improve this answer

For me was changing system dns to 127.0.0.1, prior to this is was a non-existing host.

nano /etc/resolv.conf

And write the following

domain localdomain
search localdomain
(Removed this line) ===> nameserver 10.0.0.1
(Added this line) ===> nameserver 127.0.0.1
share|improve this answer
    
For me, this file seemed to be /etc/resolv.conf (no e) –  shadow Apr 13 at 22:58

The debug output for ssh in my case just stopped for 30 seconds while it was 'connecting'. The solution turned out to be related to the DNS settings on my local system. A previous network configuration had left behind a bogus DNS server in the /etc/resolv.conf file. Replacing it with a current DNS server fixed the problem.

share|improve this answer

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.