编写完一个 javascript 项目后,我写了
git push -u origin main
但是它给了我回报:
ssh: connect to host github.com port 22: Undefined error: 0
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我该怎么办?总的来说,我对 git/github 很陌生,一直在尝试解决它,但没有运气。谢谢大家提前的回答
通过 SSH 连接到 GitHub 时,请确保您已将 SSH 密钥上传到 GitHub。本文解释了该过程。
https://docs.github.com/en/github/authenticating-to-github/connecting-to-github-with-ssh
我也遇到了这个错误,当时我在 macOS Sonoma (14.1) 上。
调试连接没有多大帮助
$ ssh -vT [email protected]
OpenSSH_9.4p1, LibreSSL 3.3.6
debug1: Reading configuration data /Users/ME/.ssh/config
debug1: /Users/ME/.ssh/config line 11: Applying options for *
debug1: /Users/ME/.ssh/config line 26: Deprecated option "useroaming"
debug1: /Users/ME/.ssh/config line 29: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 21: include /etc/ssh/ssh_config.d/* matched no files
debug1: /etc/ssh/ssh_config line 54: Applying options for *
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: auto-mux: Trying existing master
debug1: Control socket "/tmp/ssh_mux_ssh.github.com_22_git" does not exist
debug1: Connecting to ssh.github.com port 22.
ssh: connect to host ssh.github.com port 22: Undefined error: 0
我的 ssh 配置被配置为“通过
ControlMaster
多路复用 ssh 连接,因此如果没有控制套接字,它应该创建一个,但它也会失败。
为了找到问题所在,我发现 SSH 在任何主机上都失败了。但可以在主机上建立连接(通过 netcat),例如
ssh.github.com
在端口 22
。
$ nc -w 1 "140.82.121.35" 22
SSH-2.0-babeld-f8b1fc6c
“平分”
~/.ssh/config
后,我发现关键AddressFamily inet
就是原因。我不确定为什么这是一个问题,因为有 A
记录。所以解决方法是
ssh.github.com
或者
Host *
- AddressFamily inet
Host *
- AddressFamily inet
+ AddressFamily any
设置在此问题中没有发生。