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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35558649/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 03:57:01  来源:igfitidea点击:

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

gitgithub

提问by alicht

I want to push a repo from my computer to GitHub. I set the remote origin

我想将一个 repo 从我的电脑推送到 GitHub。我设置了远程原点

git remote add origin [email protected]:alicht/tweetanuber.git

and then after when I try pushing to GitHub

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

git push -u origin master

I'm greeted with this error:

我遇到了这个错误:

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.

How can I resolve this issue and push the repo on my local computer to GitHub?

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

采纳答案by Gaurav

That indicates that the gitsoftware cannot connect to Github through SSH: this often happens if your firewall, or the firewall set up by your ISP, blocks SSH connections on port 22. A quick workaround to see if this is the problem is to try the HTTPS URL provided by Github:

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

git remote add origin-https https://github.com/alicht/tweetanuber.git
git push -u origin-https master

If that works, then it's definitely your SSH port being closed. You could continue to use this alternate syntax, try to get port 22 unblocked on your computer or at your ISP, or check out the suggestion at https://stackoverflow.com/a/8081292/27310and see if that works for you.

如果可行,那么肯定是您的 SSH 端口被关闭了。您可以继续使用这种替代语法,尝试在您的计算机或 ISP 上解锁端口 22,或者查看https://stackoverflow.com/a/8081292/27310 上的建议,看看这是否适合您。

回答by Guilherme Nunes Fontans

I have had this same problem the solution was edit ~/.ssh/config e put this lines:

我遇到了同样的问题,解决方案是编辑 ~/.ssh/config e 放置以下行:

Host github.com
  Hostname ssh.github.com
  Port 443

回答by rld

The reason could be the firewall modification as you are under a network.(In which case they may deliberately block some ports): Which in my case I'm on the library and the firewall is blocking. For this work's do on terminal:

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

git config --local -e

and change this(using vim you need to type the keyboard 'i' for insert):

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

 url = [email protected]:username/repo.git

for this:

为了这:

url = https://github.com/username/repo.git

Then for save(type the keyboard ESC and then type wq! and Enter).

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

Then try to push again.

然后再次尝试推动。

回答by xab

One of possible issues is network. To verify this check if outbound port 22 is open:
netcat nc -v portquiz.net 22or with telnet telnet portquiz.net 22
Sample output for port 22

可能的问题之一是网络。要验证此检查出站端口 22 是否打开:
netcatnc -v portquiz.net 22或使用 telnettelnet portquiz.net 22
端口 22 的示例输出

nc: connectx to portquiz.net port 22 (tcp) failed: Operation timed out

Sample output for port 80

端口 80 的示例输出

found 0 associations
found 1 connections:
     1: flags=82<CONNECTED,PREFERRED>
    outif en4
    src 192.168.0.103 port 55443
    dst 5.196.70.86 port 80
    rank info not available
    TCP aux info available

Connection to portquiz.net port 80 [tcp/http] succeeded!

tip about portquiz from Link

关于来自Link 的portquiz 的提示

Possible solutions:

可能的解决方案:

  • Change git config Link
  • Use VPN
  • Use mobile hotspot
  • Open port 22
  • 更改 git 配置链接
  • 使用 VPN
  • 使用移动热点
  • 打开端口 22

回答by Sace

There may be something wrong with your firewall, I met the same problem before and I changed the remote connection method from ssh to url and fixed it.

你的防火墙可能有问题,我之前遇到过同样的问题,我将远程连接方法从 ssh 更改为 url 并修复它。

git remote set-url origin https://...
git remote set-url --push origin https://...

After that, you can continue to push it.

之后,您可以继续推动它。