SSH hangs on login after 'last update'

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?


Solution 1:

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

 .profile
 .bashrc
 .login
 .kshrc
 .tcshrc

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

/etc/profile
/etc/bashrc

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/btmp is very large.

ls -lhS /var/log/