DEV Community

Cover image for SSH Login Taking Forever? Check Your DNS Settings
Schiff Heimlich
Schiff Heimlich

Posted on

SSH Login Taking Forever? Check Your DNS Settings

SSH Login Taking Forever? Check Your DNS Settings

The Situation

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.

What Was Done

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:

Host *
    UseDNS no
Enter fullscreen mode Exit fullscreen mode

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.

Key Takeaway

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.

Conclusion

It's a small quality-of-life fix. But small fixes that you use dozens of times a day add up.

Top comments (0)