SSH Slow to Log In? Fix the Reverse DNS Delay with UseDNS no

Ever SSH’d into a machine and waited far longer than you should for the session to start? It’s especially annoying with servers on your local network, or a VM on a virtual network, that should let you in instantly.

Why SSH Login Is Slow

The SSH server is trying to look up the hostname of the connecting client (a reverse DNS lookup), and that lookup is timing out, for example because the server can’t reach a nameserver or you’re offline.

Two Simple Fixes

Option 1: Turn off the DNS lookup. Add this line to /etc/ssh/sshd_config on the server, then restart sshd:

UseDNS no

Option 2: Add the client’s IP address and hostname to the server’s /etc/hosts file so the lookup resolves immediately.