SSH hangs after authentication

Solution 1:

There are several things that can cause a hang right after SSH authentication.

However most of these will also carry other symptoms (the hang right after an SSH-auth is just the most visible symptom)

  1. As Iain mentioned, any user login scripts.
    • ~/.bashrc, ~/.bash_profile, ~/.profile, ~/.kshrc and so forth
  2. Too many processes running / restarting.
    • Something has fork()'d too many child-processes and the load (the 1/5/15 score) is too high.
  3. There is an I/O wait problem.
    • Typically caused by a dying hard-drive (common) or a badly behaving NIC (rare).
  4. A 3rd-Party PAM module hanging (eg: a non-standard Kerberos config)
    • Not always the module itself, but sometimes a service (like auditing) that has a full log-server somewhere.

Solution 2:

Does it connect directly if you use ssh -o GSSAPIAuthentication=no user@host?

If so, the system may be hanging at some point deciding on a GSSAPI method. For me, only one host did this, so I just disabled GSSAPI in ~/.ssh/config for that host:

Host badHostName
    GSSAPIAuthentication no

I learned this from http://germanrumm.eu/fixing-ssh-login-delay-how-to-disable-gssapi-with-mic-on-ubuntu-linux/ but never quite learned the cause.

Solution 3:

Yet another trouble source might be ssh clients waiting for ssh-agent (all of those configured to use it, of course). If ssh'ing anywhere gets stuck at

debug1: SSH2_MSG_NEWKEYS received

then check ps auxw | grep askpass and its dialog(s) which might have escaped your attention.

PS: this is rather not the culprit here but I haven't googled more relevant questions up so far.