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 ssh, the password prompt takes too long (almost two minutes) to appear.

Why does this happen?

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

6 Answers 6

up vote 34 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
2  
Reverse DNS lookup was my problem –  trinth Jun 24 at 19:13

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
    
fantastic.. a point re time.. the useDNS no fixed it for me.. I had password authentication and the delay was for that password entering prompt to appear.. I waited for that to appear then did ctrl-c so the 'time' didn't include me entering the password. –  barlop Sep 3 at 2:09

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

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

I don't know as much about the poster's environment as I'd like to, but for others with a similar problem, it may be an issue with sssd, which we use to tie-in ldap mojo.

This happens to me:

$ time ssh server.example.com

real  2m0.018s
user  0m0.006s
sys   0m0.004s

I have to gain access to the server (in my case via the console) then do a:

service restart sssd

After that, things just work. I haven't had time to debug the root cause, but this bandaid works for me.

share|improve this answer

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

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.