Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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

I'm having a bit of trouble. My SSH connection hangs for about 10 seconds when logging in. I've tried disabling the system info MOTD and a number of other things but it just doesn't seem to work. Trying ssh user@host -vvv doesn't help either as the log ends before the hang. It just says:

Last login: Wed Apr 17 12:52:04 2013 from 194.xx.xx.xx

Then hangs for a few seconds until it displays the prompt (user@host $) One interesting thing to note: If I press ctrl+c during this hang, it immediately solves it and the prompt flashes up so I'm guessing it's a process that is hanging. What's the best way to fix this?

share|improve this question
Check your login files - .profile, .bashrc, .login etc depending on what shell you use. – Jenny D Apr 17 '13 at 12:58
I have disabled everything in .bashrc as a test and I still get the same problem so I'm not sure – andy Apr 17 '13 at 12:59
How about /etc/profile, and other matching files? – Jenny D Apr 17 '13 at 13:00
Ahh, thank you! Moving /etc/profile.d to a new location (a crude way of disabling everything inside there) it works instantly. So I will have a look through there now and debug it. Would you mind putting this as an answer so I can mark it as accepted? :-) – andy Apr 17 '13 at 13:02
Done, with some extra explanation to make it more generally useful. – Jenny D Apr 17 '13 at 13:05
up vote 3 down vote accepted

This is usually because one of the files used by login has some function that takes a long time to return. It will commonly be either in your own home directory, where you should look at


If it's none of those, look in /etc for the same files, but usually without the dot:


and so on. The culprit will often be something that does a DNS lookup, but it might also be that you have it set to check when you last logged on, and your utmp/wtmp is very large.

share|improve this answer
But why should such a problem arise with SSH logins but not with local logins? – Hauke Laging Apr 17 '13 at 13:06
It doesn't say anywhere in the question that it doesn't happen with local logins. – Jenny D Apr 17 '13 at 13:09
I haven't tried it with local logins. The culprit was /etc/profile.d/bash_completion. I moved that and it works perfect. It just runs /etc/bash_completion which, when I ran it, took a good few seconds to do whatever it does. Does anyone know if this is vital? – andy Apr 17 '13 at 13:15
It's not vital; it's used to build helper functions that will expand and complete the command line for you - e.g. if you type "foo" and press TAB, it'll find all programs starting with "foo" for you. – Jenny D Apr 17 '13 at 13:16
@andy It's not important (OK, that assessment may differ between individuals...) but nonetheless it should not take that long. You could start it with bash -vx /etc/bash_completion in order to see what the problem is. – Hauke Laging Apr 17 '13 at 13:26

A frequent reason for this is reverse DNS lookup (which is the default). Put UseDNS no in /etc/ssh/sshd_config.

share|improve this answer
That was my first thought, but as it doesn't show up as a delay when doing ssh -vvv, and it goes away if the user presses ctrl+c while waiting for the prompt, it's unlikely to be the culprit. – Jenny D Apr 17 '13 at 13:11

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.