區域網路 SSH 連線雖通但需等待 10-30 秒才出現密碼提示。ssh -v 除錯顯示卡在 gssapi-with-mic 認證階段,提示 Cannot determine realm for numeric host address。本文提供兩種根治方案。
debug1: Next authentication method: gssapi-with-mic
debug1: An invalid name was supplied
debug1: Cannot determine realm for numeric host address
Client 端預設啟用 GSSAPIAuthentication yes,嘗試 Kerberos/GSSAPI 認證。以 IP 直連時需反解析 IP → 主機名 → Kerberos Realm,DNS 無 PTR 記錄導致長時間逾時重試。
# 編輯全域客戶端配置
sudo vim /etc/ssh/ssh_config
# 找到或新增:
GSSAPIAuthentication no
# 儲存離開,下次 ssh 即時生效
或使用者級配置 ~/.ssh/config:
Host *
GSSAPIAuthentication no
echo "192.168.12.16 ourdev" >> /etc/hosts
; 反解區域檔
16.12.168.192.in-addr.arpa. IN PTR ourdev.example.com.
dig -x 192.168.12.16 +short
# ourdev.example.com.
網路常見建議修改 Server /etc/ssh/sshd_config:
UseDNS no
實測對 Client 端 GSSAPI 逾時無效,UseDNS 僅控制 Server 端是否對 Client IP 做反解析記錄日誌/權限檢查,不影響 Client 發起的 GSSAPI 流程。
ssh -v 192.168.12.16
# debug1: Authentications that can continue: publickey,password
# debug1: Next authentication method: publickey
# debug1: Next authentication method: password
# password: (立即出現,無延遲)
Host *
GSSAPIAuthentication no
ForwardAgent no
ForwardX11 no
ServerAliveInterval 60
ServerAliveCountMax 3
StrictHostKeyChecking accept-new
UserKnownHostsFile ~/.ssh/known_hosts
Compression yes
ControlMaster auto
ControlPath ~/.ssh/cm-%r@%h:%p
ControlPersist 10m
# /etc/ssh/sshd_config
UseDNS no
GSSAPIAuthentication no
ClientAliveInterval 60
ClientAliveCountMax 3
MaxAuthTries 3
LoginGraceTime 30
PermitRootLogin prohibit-password
PasswordAuthentication no
PubkeyAuthentication yes
關閉 Client 端 GSSAPIAuthentication 是解決 SSH 連線緩慢最直接、相容性最高的方案;配合 DNS 反解析完善,從根源消除 Kerberos Realm 解析失敗導致的逾時等待。