SSH Hangs Before Password Prompt – DNS Issue

domain-name-systemssh

I am trying to SSH onto a linux server:

ssh -X -l <username> <address>

When I am connected through my home WiFi router (which is very fast), this command might hang indefinitely. (For others, such as when I use my phone's mobile data, it connects immediately 100% of the time). If I repeat the ssh command enough times (in the order of 100 times), by executing the command and then immediately hitting control c if it doesn't prompt, I can usually get it to respond, although this is not failsafe. When it finally works, the prompt is immediate, and the terminal is very responsive. If I let the ssh command hang waiting for the password prompt, it sometimes will prompt my password after a few seconds to a few minutes, but it also might hang for an hour.

I am not an administrator on the server I am trying to connect to, thus I cannot enable UseDNS no on the server. Is this definitely the problem? Why does it treat my mobile data differently from my home WiFi?

Update

Here is the sanitized output when run using -vvv

debug1: Reading configuration data /Users/userName/.ssh/config
debug2: checking match for 'exec "/usr/local/bin/sft resolve -q  %h"' host address originally address
debug1: Executing command: '/usr/local/bin/sft resolve -q  address'
debug3: command returned status 126
debug3: /Users/userName/.ssh/config line 2: not matched 'exec "/usr/local/bin/sft resolve -q  address"' 
debug2: match not found
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 47: Applying options for *
debug1: Connecting to address port 22.

Here it hangs.

Best Answer

Make sure you have the follownig enabled in your sshd_config file.

USeDNS no