On most of my Ubuntu servers, I found that logging in took 15-30 seconds when using SSH. Eventually I narrowed down the problem to three different causes.
The hostname took a while to lookup
My server hostnames look like this: someserver.sparkcreek.ca. Apparently the DNS lookup for this was taking a while, when it didn’t need to. I just added two aliases to my
/etc/hosts file, for someserver and someserver.sparkcreek.ca. My
/etc/hosts file now looks like this:
127.0.0.1 localhost someserver.sparkcreek.ca someserver
SSH reverse DNS lookups took a while
SSHd will attempt to do a reverse DNS lookup on any IP connecting to it, but most client machines out there won’t have reverse DNS configured (even if they do, it’s not something you need). You can disable this by adding
UseDNS No to your
GSSAPIAuthentication no to your
SSH logins now take ~2 seconds instead of 15-30 seconds.