Domain-Name-System

SSH 通常在密碼提示之前掛起

  • March 15, 2022

我正在嘗試通過 SSH 連接到 linux 伺服器:

ssh -X -l <username> <address>

當我通過家庭 WiFi 路由器(速度非常快)連接時,此命令可能會無限期掛起。(對於其他人,例如當我使用手機的移動數據時,它會 100% 立即連接)。如果我重複 ssh 命令足夠多的時間(大約 100 次),通過執行命令,如果沒有提示,然後立即點擊 control c,我通常可以讓它響應,儘管這不是故障安全的。當它最終工作時,提示是立即的,並且終端非常敏感。如果我讓 ssh 命令掛起等待密碼提示,它有時會在幾秒鐘到幾分鐘後提示我的密碼,但它也可能會掛起一個小時。

我不是我嘗試連接的伺服器的管理員,因此我無法UseDNS no在伺服器上啟用。這絕對是問題嗎?為什麼它對待我的移動數據的方式與我的家庭 WiFi 不同?

更新

這是執行時經過清理的輸出-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.

它掛在這裡。

解決此問題的最簡單方法是使用伺服器的 IP 地址,而不是依靠 DNS 為您找到它。所以:

ssh -Xl <username> 123.456.789.0

似乎有點微不足道,但如果你是一個沒有經驗的網路人,那麼你可能不會想到這一點(因為我沒有)

確保在 sshd_config 文件中啟用了 follownig。

USeDNS no

引用自:https://serverfault.com/questions/1092499