Score:0

SSH usually hangs before password prompt

cn flag

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.

asktyagi avatar
in flag
try running ssh in verbose more with -vvv option, also check destination server logs as well if you see any ssh or system health related issues.
cn flag
I updated the question with -vvv output, I really don't know much about this so it's difficult for me to glean a lot of information from them..
in flag
A delay with SSH logins is usually associated with DNS problems on the server side. The SSH server tries to resolve the address of the connecting client.
asktyagi avatar
in flag
try `strace` to dig local system call or local system delay by prefixing to ssh command. Also check if other methods of checking port gives you faster response, another check will be your ssh config if you have change something out of the box.
Score:1
us flag

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

USeDNS no
cn flag
Thanks for the tip but not relevant if you don't have root privileges on the server
Score:1
cn flag

The easiest way to get around this is to use the server's ip address rather than relying on DNS to find it for you. So:

ssh -Xl <username> 123.456.789.0

Seems kind of trivial but if you're an inexperienced networker then you might not have thought of this (as I hadn't)

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.