HowTo: Fix slow password prompting when doing SSH logins

You may notice on some systems you build that when you SSH into them, there seems to be a long delay before the system prompts you for your password. In a time-sensitive situation, this gets real frustrating, real fast.

Here’s how to fix it.

The issue is caused by the box you are SSHing into trying to resolve your IP address to a DNS name for the logs. We don’t really need this (especially for non-public servers), so we may as well disable it, drastically speeding up the time it takes for the box to prompt you for your password in the process (so drastic it becomes instant, in fact).

  1. Login to your box as normal via SSH.
  2. Type in at the dollar prompt:

    $ sudo nano /etc/ssh/ssh_config
  3. A text editor showing you the SSH server config will appear. Scroll right to the very bottom of the file.
  4. Now add the following line in (indent it to match the existing lines with a few spaces at the front):

    UseDNS no
  5. Save your changes by pressing CTRL+X, then “Y” and then Enter.
  6. Restart the SSH server with the following command (won’t affect your existing session):

    $ sudo service ssh restart
  7. Log out and test logging in via SSH again. This time the password prompt will appear immediately.
  8. Pat yourself on the back. You’re done.

This fix applies to any version of Ubuntu (or just about any distro, for that matter).