
SSH登入需要15秒
我有兩個設備:
- 適用於 Windows 的 WSL 運作:OpenSSH_7.6p1 Ubuntu-4ubuntu0.5、OpenSSL 1.0.2n 2017 年 12 月 7 日
- Raspbian 運行:OpenSSH_7.9p1 Raspbian-10+deb10u2,OpenSSL 1.1.1d 2019 年 9 月 10 日
還有一台centos 8伺服器。
第一個 (WSL) 需要 15 秒才能透過密碼或公鑰登入伺服器。 Raspbian 是中間的。我使用 IP 從兩個裝置進行連線。
我已將伺服器的 ssh 守護程序日誌設定為 debug3,我看不到兩次登入之間有太大差異,但我看到這裡有 15 秒的延遲:
Oct 17 09:13:20 localhost sshd[2080]: debug3: userauth_finish: failure partial=0 next methods="publickey,gssapi-keyex,gssapi-with-mic,password" [preauth]
Oct 17 09:13:20 localhost sshd[2080]: debug3: send packet: type 51 [preauth]
Oct 17 09:13:20 localhost sshd[1979]: debug2: channel 0: rcvd adjust 50867
Oct 17 09:13:36 localhost sshd[2080]: debug3: receive packet: type 50 [preauth]
Oct 17 09:13:36 localhost sshd[2080]: debug1: userauth-request for user marco service ssh-connection method publickey [preauth]
我該尋找什麼線索?
這是 ssh -vvv 輸出,我添加了時間戳
[2021-10-21 19:53:13] debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
[2021-10-21 19:53:13] debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
[2021-10-21 19:53:13] debug3: preferred gssapi-with-mic,publickey,keyboard-interactive,password
[2021-10-21 19:53:13] debug3: authmethod_lookup gssapi-with-mic
[2021-10-21 19:53:13] debug3: remaining preferred: publickey,keyboard-interactive,password
[2021-10-21 19:53:13] debug3: authmethod_is_enabled gssapi-with-mic
[2021-10-21 19:53:13] debug1: Next authentication method: gssapi-with-mic
[2021-10-21 19:53:22] debug1: Unspecified GSS failure. Minor code may provide more information
[2021-10-21 19:53:22] No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)
[2021-10-21 19:53:22]
[2021-10-21 19:53:22]
[2021-10-21 19:53:33] debug1: Unspecified GSS failure. Minor code may provide more information
[2021-10-21 19:53:33] No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_1000)
[2021-10-21 19:53:33]
[2021-10-21 19:53:33]
[2021-10-21 19:53:33] debug2: we did not send a packet, disable method
[2021-10-21 19:53:33] debug3: authmethod_lookup publickey
[2021-10-21 19:53:33] debug3: remaining preferred: keyboard-interactive,password
[2021-10-21 19:53:33] debug3: authmethod_is_enabled publickey
[2021-10-21 19:53:33] debug1: Next authentication method: publickey
[2021-10-21 19:53:33] debug1: Offering public key: /home/marco/.ssh/id_rsa RSA SHA256:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
[2021-10-21 19:53:33] debug3: send packet: type 50
[2021-10-21 19:53:34] debug2: we sent a publickey packet, wait for reply
[2021-10-21 19:53:34] debug3: receive packet: type 51
[2021-10-21 19:53:34] debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
[2021-10-21 19:53:34] debug1: Trying private key: /home/marco/.ssh/id_dsa
[2021-10-21 19:53:34] debug3: no such identity: /home/marco/.ssh/id_dsa: No such file or directory
[2021-10-21 19:53:34] debug1: Trying private key: /home/marco/.ssh/id_ecdsa
[2021-10-21 19:53:34] debug3: no such identity: /home/marco/.ssh/id_ecdsa: No such file or directory
[2021-10-21 19:53:34] debug1: Trying private key: /home/marco/.ssh/id_ecdsa_sk
[2021-10-21 19:53:34] debug3: no such identity: /home/marco/.ssh/id_ecdsa_sk: No such file or directory
[2021-10-21 19:53:34] debug1: Trying private key: /home/marco/.ssh/id_ed25519
[2021-10-21 19:53:34] debug3: no such identity: /home/marco/.ssh/id_ed25519: No such file or directory
[2021-10-21 19:53:34] debug1: Trying private key: /home/marco/.ssh/id_ed25519_sk
[2021-10-21 19:53:34] debug3: no such identity: /home/marco/.ssh/id_ed25519_sk: No such file or directory
[2021-10-21 19:53:34] debug1: Trying private key: /home/marco/.ssh/id_xmss
[2021-10-21 19:53:34] debug3: no such identity: /home/marco/.ssh/id_xmss: No such file or directory
[2021-10-21 19:53:34] debug2: we did not send a packet, disable method
[2021-10-21 19:53:34] debug3: authmethod_lookup password
[2021-10-21 19:53:34] debug3: remaining preferred: ,password
[2021-10-21 19:53:34] debug3: authmethod_is_enabled password
[2021-10-21 19:53:34] debug1: Next authentication method: password
答案1
嘗試停用 GSSAPIAuthentication。sshd_config
在 WSL 中編輯文件並將其GSSAPIAuthentication
從更改yes
為no
.
sudo nano /etc/ssh/sshd_config
儲存變更並重新啟動 SSH 守護程式。
sudo systemctl restart sshd
來源: 技術一覽