gpt4 book ai didi

git - Mac : SSH doesn't work anymore without changing something

转载 作者:行者123 更新时间:2023-12-02 14:11:59 24 4
gpt4 key购买 nike

在网上搜索了一天没有一个好的解决方案后,我在这里告诉你我的问题。

三天前,我设置了一个 SSH key 来使用 git 和 SSH。一切正常,我能够将所有内容推送和 pull 到 GitHub。从昨天开始,我不能再这样做了。我总是得到同样的错误(如下所示)。 SSH-key 是 ssh-agent 的一部分,配置文件没有更改,甚至无法通过 SSH 正常连接到 GitHub。也尝试了其他项目和其他 repos 并得到了同样的错误。最近几天我没有更新 Sierra 或其他内容,所以这也不是原因。

终端输入和输出:

User-MBP:data-analysis user$ git push -v origin master
Pushing to git@github.com:Username/data-analysis.git
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

正常的 SSH 连接:
User-MBP:data-analysis user$ ssh -v git@github.com
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 443.
debug1: Connection established.
debug1: identity file /Users/user/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/user/.ssh/id_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
ssh_exchange_identification: Connection closed by remote host

感谢您的帮助!

更新

将端口更改回 22 以获得以下信息:
User-MBP:data-analysis user$ git push origin master
ssh: connect to host github.com port 22: Connection refused
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.


User-MBP:data-analysis user$ ssh -v git@github.com
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/user/.ssh/config
debug1: /Users/user/.ssh/config line 1: Applying options for *
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to github.com [192.30.253.113] port 22.
debug1: connect to address 192.30.253.113 port 22: Connection refused
debug1: Connecting to github.com [192.30.253.112] port 22.
debug1: connect to address 192.30.253.112 port 22: Connection refused
ssh: connect to host github.com port 22: Connection refused

最佳答案

debug1: Connecting to github.com [192.30.253.113] port 443.
...
ssh_exchange_identification: Connection closed by remote host

“ssh_exchange_identification: Connection closed by remote host”表示远程服务器在接受TCP连接后故意立即关闭它。尚未进行 key 交换或身份验证尝试。

您正在连接到端口 443 (HTTPS) 而不是端口 22 (SSH)。当我尝试它时,我得到了同样的错误:
$ ssh -p 443 git@github.com
ssh_exchange_identification: Connection closed by remote host
$ ssh git@github.com
Permission denied (publickey).

连接到端口 443 会产生与您得到的相同的错误。连接到正确的 ssh 端口至少会尝试进行身份验证(因为我没有在 github 上设置而失败)。

显然 github 不接受端口 443 上的 ssh 连接。而是连接到端口 22。

编辑:
ssh: connect to host github.com port 22: Connection refused

“连接被拒绝”意味着您没有与远程服务器建立 TCP 连接。在这种情况下,我的猜测是由于本地网络中的防火墙阻止了传出的 SSH 连接。这可能是您首先使用端口 443 进行 SSH 的原因。

正如@phd 所指出的,github 支持 ssh 到端口 443,但您必须安排连接到“ssh.github.com”而不仅仅是“github.com”。引用 github's documentation .

或者,您可以与本地网络管理员讨论允许 ssh 访问 github。

关于git - Mac : SSH doesn't work anymore without changing something,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47249917/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com