git 操作超时,但 ssh 工作正常

git 操作超时,但 ssh 工作正常

我正在使用带有 WSL2 的 Ubuntu 22.04.4 LTS。

以前我的 git 工作起来很有趣,但是最近,如果我尝试 git pull,它会给出:

~/xxx main ❯ git pull origin main                                                                         
ssh: connect to host github.com port 22: Connection timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

但是,如果我明确让 git 使用

env GIT_SSH_COMMAND="ssh" git pull origin main

一切正常。并且“ssh -T[电子邮件保护]“命令同样有效。

我也试过

env GIT_SSH_COMMAND="ssh -vvv" git pull origin main

这是输出,我没有发现任何异常:

OpenSSH_8.9p1 Ubuntu-3ubuntu0.6, OpenSSL 3.0.2 15 Mar 2022
debug1: Reading configuration data /home/zao/.ssh/config
debug1: /home/zao/.ssh/config line 17: Applying options for github.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: include /etc/ssh/ssh_config.d/*.conf matched no files
debug1: /etc/ssh/ssh_config line 21: Applying options for *
debug3: expanded UserKnownHostsFile '~/.ssh/known_hosts' -> '/home/zao/.ssh/known_hosts'
debug2: resolving "ssh.github.com" port 22
debug3: resolve_host: lookup ssh.github.com:22
debug3: ssh_connect_direct: entering
debug1: Connecting to ssh.github.com [20.205.243.160] port 22.
debug3: set_sock_tos: set socket 3 IP_TOS 0x10
debug1: Connection established.
debug1: identity file /home/zao/.ssh/id_rsa type 0
debug1: identity file /home/zao/.ssh/id_rsa-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_8.9p1 Ubuntu-3ubuntu0.6
debug1: Remote protocol version 2.0, remote software version babeld-05989c77
debug1: compat_banner: no match: babeld-05989c77
debug2: fd 3 setting O_NONBLOCK
debug1: Authenticating to ssh.github.com:22 as 'git'
debug3: record_hostkey: found key type ED25519 in file /home/zao/.ssh/known_hosts:5
debug3: record_hostkey: found key type RSA in file /home/zao/.ssh/known_hosts:6
debug3: record_hostkey: found key type ECDSA in file /home/zao/.ssh/known_hosts:7
debug3: load_hostkeys_file: loaded 3 keys from ssh.github.com
debug3: order_hostkeyalgs: have matching best-preference key type [email protected], using HostkeyAlgorithms verbatim
debug3: send packet: type 20
debug1: SSH2_MSG_KEXINIT sent
debug3: receive packet: type 20
debug1: SSH2_MSG_KEXINIT received
debug2: local client KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,[email protected],diffie-hellman-group-exchange-sha256,diffie-hellman-group16-sha512,diffie-hellman-group18-sha512,diffie-hellman-group14-sha256,ext-info-c,[email protected]
debug2: host key algorithms: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected],rsa-sha2-512,rsa-sha2-256
debug2: ciphers ctos: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: ciphers stoc: [email protected],aes128-ctr,aes192-ctr,aes256-ctr,[email protected],[email protected]
debug2: MACs ctos: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: MACs stoc: [email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug2: peer server KEXINIT proposal
debug2: KEX algorithms: curve25519-sha256,[email protected],ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,[email protected]
debug2: host key algorithms: ssh-ed25519,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa
debug2: ciphers ctos: [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
debug2: ciphers stoc: [email protected],[email protected],[email protected],aes256-ctr,aes192-ctr,aes128-ctr
debug2: MACs ctos: [email protected],[email protected],hmac-sha2-512,hmac-sha2-256
debug2: MACs stoc: [email protected],[email protected],hmac-sha2-512,hmac-sha2-256
debug2: compression ctos: none,[email protected],zlib
debug2: compression stoc: none,[email protected],zlib
debug2: languages ctos:
debug2: languages stoc:
debug2: first_kex_follows 0
debug2: reserved 0
debug3: kex_choose_conf: will use strict KEX ordering
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug3: send packet: type 30
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug3: receive packet: type 31
debug1: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
debug3: record_hostkey: found key type ED25519 in file /home/zao/.ssh/known_hosts:5
debug3: record_hostkey: found key type RSA in file /home/zao/.ssh/known_hosts:6
debug3: record_hostkey: found key type ECDSA in file /home/zao/.ssh/known_hosts:7
debug3: load_hostkeys_file: loaded 3 keys from ssh.github.com
debug1: Host 'ssh.github.com' is known and matches the ED25519 host key.
debug1: Found key in /home/zao/.ssh/known_hosts:5
debug3: send packet: type 21
debug1: ssh_packet_send2_wrapped: resetting send seqnr 3
debug2: ssh_set_newkeys: mode 1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug3: receive packet: type 21
debug1: ssh_packet_read_poll2: resetting read seqnr 3
debug1: SSH2_MSG_NEWKEYS received
debug2: ssh_set_newkeys: mode 0
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: /home/zao/.ssh/id_rsa RSA SHA256:nEM42NAlhXlckBTlu9SbUFYJO2B2D883u4wZU0khU+U explicit
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],[email protected],ssh-ed25519,ecdsa-sha2-nistp521,ecdsa-sha2-nistp384,ecdsa-sha2-nistp256,rsa-sha2-512,rsa-sha2-256,ssh-rsa>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred publickey
debug3: authmethod_lookup publickey
debug3: remaining preferred:
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /home/zao/.ssh/id_rsa RSA SHA256:nEM42NAlhXlckBTlu9SbUFYJO2B2D883u4wZU0khU+U explicit
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 60
debug1: Server accepts key: /home/zao/.ssh/id_rsa RSA SHA256:nEM42NAlhXlckBTlu9SbUFYJO2B2D883u4wZU0khU+U explicit
debug3: sign_and_send_pubkey: using publickey with RSA SHA256:nEM42NAlhXlckBTlu9SbUFYJO2B2D883u4wZU0khU+U
debug3: sign_and_send_pubkey: signing using rsa-sha2-512 SHA256:nEM42NAlhXlckBTlu9SbUFYJO2B2D883u4wZU0khU+U
Enter passphrase for key '/home/zao/.ssh/id_rsa':
debug3: send packet: type 50
debug3: receive packet: type 52
Authenticated to ssh.github.com ([20.205.243.160]:22) using "publickey".
debug2: fd 4 setting O_NONBLOCK
debug1: channel 0: new [client-session]
debug3: ssh_session2_open: channel_new: 0
debug2: channel 0: send open
debug3: send packet: type 90
debug1: Entering interactive session.
debug1: pledge: filesystem
debug3: receive packet: type 80
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug3: client_input_hostkeys: received RSA key SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s
debug3: client_input_hostkeys: received ECDSA key SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM
debug3: client_input_hostkeys: received ED25519 key SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
debug1: client_input_hostkeys: searching /home/zao/.ssh/known_hosts for ssh.github.com / (none)
debug3: hostkeys_foreach: reading file "/home/zao/.ssh/known_hosts"
debug3: hostkeys_find: found ssh-ed25519 key at /home/zao/.ssh/known_hosts:5
debug3: hostkeys_find: found ssh-rsa key at /home/zao/.ssh/known_hosts:6
debug3: hostkeys_find: found ecdsa-sha2-nistp256 key at /home/zao/.ssh/known_hosts:7
debug3: client_input_hostkeys: 3 server keys: 0 new, 3 retained, 0 incomplete match. 0 to remove
debug1: client_input_hostkeys: no new or deprecated keys from server
debug3: receive packet: type 91
debug2: channel_input_open_confirmation: channel 0: callback start
debug2: fd 3 setting TCP_NODELAY
debug3: set_sock_tos: set socket 3 IP_TOS 0x08
debug2: client_session2_setup: id 0
debug1: Sending environment.
debug3: Ignored env CONDA_PROMPT_MODIFIER
debug3: Ignored env HTTPS_PROXY
debug3: Ignored env GIT_SSH_COMMAND
debug3: Ignored env USER
debug3: Ignored env no_proxy
debug3: Ignored env GIT_EXEC_PATH
debug3: Ignored env SHLVL
debug3: Ignored env WT_PROFILE_ID
debug3: Ignored env CONDA_SHLVL
debug3: Ignored env HOME
debug3: Ignored env LESS
debug3: Ignored env OLDPWD
debug3: Ignored env NO_PROXY
debug3: Ignored env NVM_BIN
debug3: Ignored env LSCOLORS
debug3: Ignored env NVM_INC
debug3: Ignored env ZSH
debug3: Ignored env PAGER
debug3: Ignored env P9K_TTY
debug3: Ignored env WSL_DISTRO_NAME
debug3: Ignored env _CE_M
debug3: Ignored env NVM_DIR
debug3: Ignored env WAYLAND_DISPLAY
debug3: Ignored env https_proxy
debug3: Ignored env LOGNAME
debug3: Ignored env NAME
debug3: Ignored env PULSE_SERVER
debug3: Ignored env WSL_INTEROP
debug3: Ignored env _
debug3: Ignored env _P9K_SSH_TTY
debug3: Ignored env http_proxy
debug1: channel 0: setting env GIT_PROTOCOL = "version=2"
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env TERM
debug3: Ignored env _CE_CONDA
debug3: Ignored env PATH
debug3: Ignored env WT_SESSION
debug3: Ignored env XDG_RUNTIME_DIR
debug3: Ignored env DISPLAY
debug1: channel 0: setting env LANG = "C.UTF-8"
debug2: channel 0: request env confirm 0
debug3: send packet: type 98
debug3: Ignored env LS_COLORS
debug3: Ignored env CONDA_PYTHON_EXE
debug3: Ignored env SHELL
debug3: Ignored env CONDA_DEFAULT_ENV
debug3: Ignored env GIT_REFLOG_ACTION
debug3: Ignored env P9K_SSH
debug3: Ignored env PWD
debug3: Ignored env CONDA_EXE
debug3: Ignored env NVM_CD_FLAGS
debug3: Ignored env _P9K_TTY
debug3: Ignored env HTTP_PROXY
debug3: Ignored env CONDA_PREFIX
debug3: Ignored env HOSTTYPE
debug3: Ignored env WSL2_GUI_APPS_ENABLED
debug3: Ignored env WSLENV
debug1: Sending command: git-upload-pack 'xxx.git'
debug2: channel 0: request exec confirm 1
debug3: send packet: type 98
debug2: channel_input_open_confirmation: channel 0: callback done
debug2: channel 0: open confirm rwindow 32000 rmax 35000
debug3: receive packet: type 99
debug2: channel_input_status_confirm: type 99 id 0
debug2: exec request accepted on channel 0
debug2: channel 0: rcvd adjust 1248305
From github.com:xxx/xxxx
 * branch            main       -> FETCH_HEAD
debug2: channel 0: read failed rfd 4 maxlen 32768: Broken pipe
debug2: channel 0: read failed
debug2: chan_shutdown_read: channel 0: (i0 o0 sock -1 wfd 4 efd 6 [write])
debug2: channel 0: input open -> drain
debug2: channel 0: ibuf empty
debug2: channel 0: send eof
debug3: send packet: type 96
debug2: channel 0: input drain -> closed
debug3: receive packet: type 98
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug3: receive packet: type 96
debug2: channel 0: rcvd eof
debug2: channel 0: output open -> drain
debug2: channel 0: obuf empty
debug2: chan_shutdown_write: channel 0: (i3 o1 sock -1 wfd 5 efd 6 [write])
debug2: channel 0: output drain -> closed
debug3: receive packet: type 97
debug2: channel 0: rcvd close
debug3: channel 0: will not send data after close
debug2: channel 0: almost dead
debug2: channel 0: gc: notify user
debug2: channel 0: gc: user detached
debug2: channel 0: send close
debug3: send packet: type 97
debug2: channel 0: is dead
debug2: channel 0: garbage collecting
debug1: channel 0: free: client-session, nchannels 1
debug3: channel 0: status: The following connections are open:
  #0 client-session (t4 r43 i3/0 o3/0 e[write]/0 fd -1/-1/6 sock -1 cc -1 io 0x00/0x00)

debug3: send packet: type 1
Transferred: sent 3676, received 3072 bytes, in 1.3 seconds
Bytes per second: sent 2742.8, received 2292.2
debug1: Exit status 0
Already up to date.

谢谢任何建议或帮助。


正如@muru 所建议的,我已经尝试过strace -fe trace=process git pull,输出是:

execve("/usr/bin/git", ["git", "pull", "origin", "main"], 0x7ffcac11a158 /* 50 vars */) = 0
clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLDstrace: Process 410 attached
, child_tidptr=0x7f9ecb70ea10) = 410
[pid   410] execve("/usr/lib/git-core/git", ["/usr/lib/git-core/git", "fetch", "--update-head-ok", "origin", "main"], 0x5567b34029b0 /* 53 vars */) = 0
[pid   409] wait4(410,  <unfinished ...>
[pid   410] clone(child_stack=NULL, flags=CLONE_CHILD_CLEARTID|CLONE_CHILD_SETTID|SIGCHLD, child_tidptr=0x7efd0117ba10) = 411
strace: Process 411 attached
[pid   411] execve("/bin/sh", ["/bin/sh", "-c", "ssh -i ~/.ssh/id_rsa -F /dev/nul"..., "ssh -i ~/.ssh/id_rsa -F /dev/nul"..., "-o", "SendEnv=GIT_PROTOCOL", "[email protected]", "git-upload-pack 'zyHan2077/Major"...], 0x564008ed5ff0 /* 53 vars */) = 0
[pid   411] vfork(strace: Process 412 attached
 <unfinished ...>
[pid   412] execve("/usr/bin/ssh", ["ssh", "-i", "/home/zao/.ssh/id_rsa", "-F", "/dev/null", "-o", "SendEnv=GIT_PROTOCOL", "[email protected]", "git-upload-pack 'zyHan2077/Major"...], 0x5603ab58b078 /* 53 vars */ <unfinished ...>
[pid   411] <... vfork resumed>)        = 412
[pid   412] <... execve resumed>)       = 0
[pid   411] wait4(-1, ssh: connect to host github.com port 22: Connection timed out
 <unfinished ...>
[pid   412] exit_group(255)             = ?
[pid   412] +++ exited with 255 +++
[pid   411] <... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 255}], 0, NULL) = 412
[pid   411] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=412, si_uid=1000, si_status=255, si_utime=0, si_stime=1} ---
[pid   411] wait4(-1, 0x7ffeb6de7ebc, WNOHANG, NULL) = -1 ECHILD (No child processes)
[pid   411] exit_group(255)             = ?
[pid   411] +++ exited with 255 +++
[pid   410] --- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=411, si_uid=1000, si_status=255, si_utime=0, si_stime=0} ---
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
[pid   410] exit_group(128)             = ?
[pid   410] +++ exited with 128 +++
<... wait4 resumed>[{WIFEXITED(s) && WEXITSTATUS(s) == 128}], 0, NULL) = 410
--- SIGCHLD {si_signo=SIGCHLD, si_code=CLD_EXITED, si_pid=410, si_uid=1000, si_status=128, si_utime=0, si_stime=1} ---
exit_group(1)                           = ?
+++ exited with 1 +++

相关内容