Tools: Essential Guide: SSH Login Taking Forever? Check Your DNS Settings

Tools: Essential Guide: SSH Login Taking Forever? Check Your DNS Settings

SSH Login Taking Forever? Check Your DNS Settings

The Situation

What Was Done

Key Takeaway

Conclusion You type ssh user@server, hit enter, and wait. And wait. Ten seconds later, the password prompt finally appears. It's not network latency — ping is fine. It's not the server — other people connect instantly. It's just your SSH client hanging for no obvious reason. This is one of those problems that wastes a small amount of time on a regular basis, which adds up to a large amount of time over months. The culprit is almost always DNS resolution. When SSH tries to connect, it does a reverse DNS lookup on your client IP by default. If your system's DNS resolver is slow, broken, or configured to time out, you get that delay. The fix is straightforward: disable DNS lookups in your SSH client. Add this to ~/.ssh/config: That's it. Restart your SSH connection and the delay disappears. If you're curious why this happens: SSH calls getaddrinfo() which goes through your resolver. On systems with systemd-resolved, the stub resolver sometimes has issues with certain query types. On VPS environments, DNS can route through slow upstream resolvers. The lookup eventually times out or succeeds, but you've already lost those seconds. Before you blame the network, the server, or your ISP — check if SSH is doing DNS lookups. The UseDNS no option is a one-line fix that pays off every single time you connect. If you're managing servers and want to help your users, make sure reverse DNS works correctly for your IP ranges. That way, users who keep UseDNS on (the default) won't suffer either. It's a small quality-of-life fix. But small fixes that you use dozens of times a day add up. Templates let you quickly answer FAQs or store snippets for re-use. Are you sure you want to ? It will become hidden in your post, but will still be visible via the comment's permalink. Hide child comments as well For further actions, you may consider blocking this person and/or reporting abuse

Command

Copy

$ ssh user@server ~/.ssh/config Host * UseDNS no Host * UseDNS no Host * UseDNS no getaddrinfo()