GitHub错误 - "ssh:连接到主机github.com端口22:操作超时致命:无法从远程存储库读取."

ali*_*cht 17 git github

我想把我的电脑仓库推到GitHub.我设置了远程原点

git remote add origin git@github.com:alicht/tweetanuber.git
Run Code Online (Sandbox Code Playgroud)

然后在我尝试推送到GitHub之后

git push -u origin master
Run Code Online (Sandbox Code Playgroud)

我遇到了这个错误:

ssh: connect to host github.com port 22: Operation timed out
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

如何解决此问题并将本地计算机上的repo推送到GitHub?

小智 29

我也有同样的问题,解决方法是编辑〜/ .ssh / config,将以下行:

Host github.com
  Hostname ssh.github.com
  Port 443
Run Code Online (Sandbox Code Playgroud)

  • 这会将您的SSH客户端配置为在端口443而不是标准端口22上使用github的ssh服务器。通常不会阻塞443,因为它通常用于SSL流量https://help.github.com/en/articles/using-ssh通过https端口 (4认同)

Gau*_*rav 15

这表明该git软件无法通过SSH连接到Github:如果您的防火墙或ISP设置的防火墙阻止端口22上的SSH连接,通常会发生这种情况.快速解决方法是查看是否存在问题,请尝试使用HTTPS Github提供的URL:

git remote add origin-https https://github.com/alicht/tweetanuber.git
git push -u origin-https master
Run Code Online (Sandbox Code Playgroud)

如果可行,那么肯定是您的SSH端口被关闭了.您可以继续使用此备用语法,尝试在您的计算机或ISP上取消阻止端口22,或查看/sf/answers/565690471/上的建议,看看它是否适合您.

  • GitHub 在 2021 年 8 月阻止用户名/密码身份验证后,HTTPS 替代方案不再有效 (3认同)
  • 在尝试 HTTPS(成功)并重试 SSH 后,它成功工作了。 (2认同)

rld*_*rld 7

原因可能是您在网络下修改了防火墙。(在这种情况下,他们可能会故意阻止某些端口):在我的情况下,我在图书馆,防火墙正在阻止。对于这项工作在终端上做:

git config --local -e
Run Code Online (Sandbox Code Playgroud)

并更改此设置(使用 vim,您需要输入键盘“i”进行插入):

 url = git@github.com:username/repo.git
Run Code Online (Sandbox Code Playgroud)

为了这:

url = https://github.com/username/repo.git
Run Code Online (Sandbox Code Playgroud)

然后保存(输入键盘 ESC 然后输入 wq! 和 Enter)。

然后再次尝试推动。


Sar*_*nan 5

这是因为我的网络,它阻止了呼叫。当我切换到我的热点时,它开始工作!