git ssh:连接到主机 github.com 端口 22:连接超时

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/15589682/
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-10 15:49:01  来源:igfitidea点击:

ssh: connect to host github.com port 22: Connection timed out

gitssh

提问by Vihari Piratla

I am under a proxy and I am pushing in to git successfully for quite a while.
Now I am not able to push into git all of a sudden.
I have set the RSA key and the proxy and double checked them, with no avail and git is throwing me the error shown in the title of the page.

我在一个代理下,我成功地推动了 git 很长一段时间。
现在我无法突然进入 git。
我已经设置了 RSA 密钥和代理并仔细检查了它们,但无济于事,git 向我抛出了页面标题中显示的错误。

回答by Vihari Piratla

The reason could be the firewall modification as you are under a network.(In which case they may deliberately block some ports)
To double check if this is the reason ... do

原因可能是您在网络下修改了防火墙。(在这种情况下,他们可能会故意阻止某些端口)
要仔细检查这是否是原因...

ssh -T [email protected]

this should timeout. If that's the case use http protocol instead of ssh this way
just change your url in the config file to http.
Here is how :-

这应该超时。如果是这种情况,请以这种方式使用 http 协议而不是 ssh,
只需将配置文件中的 url 更改为 http。
这是如何: -

git config --local -e

change entry of

更改条目

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

to

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

回答by Mahan_F

For my case none of the suggested solutions worked so I tried to fix it myself and I got it resolved.

对于我的情况,建议的解决方案都没有奏效,所以我尝试自己修复它并解决了它。

For me I am getting this error on my AWS EC2 UBUNTU instance, what I did to resolve it was to edit the git config (or add it if it does not exist).

对我来说,我在我的 AWS EC2 UBUNTU 实例上收到此错误,我为解决它所做的是编辑 git 配置(如果它不存在,则添加它)。

sudo nano ~/.ssh/config

sudo nano ~/.ssh/config

And I added the following

我添加了以下内容

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

Then, run the command ssh -T [email protected]to confirm if the issue is fixed.

然后,运行命令ssh -T [email protected]以确认问题是否已解决。

According to this

根据这个

Sometimes, firewalls refuse to allow SSH connections entirely. If using HTTPS cloning with credential caching is not an option, you can attempt to clone using an SSH connection made over the HTTPS port. Most firewall rules should allow this, but proxy servers may interfere

有时,防火墙完全拒绝允许 SSH 连接。如果无法将 HTTPS 克隆与凭据缓存结合使用,您可以尝试使用通过 HTTPS 端口建立的 SSH 连接进行克隆。大多数防火墙规则应该允许这样做,但代理服务器可能会干扰

Hopefully this helps anyone else who's having the same issue I did.

希望这可以帮助其他遇到同样问题的人。

回答by user224540

Basic URL Rewriting

基本的 URL 重写

Git provides a way to rewrite URLs using git config. Simply issue the following command:

Git 提供了一种使用 git config 重写 URL 的方法。只需发出以下命令:

git config --global url."https://".insteadOf git://

Now, as if by magic, all git commands will perform a substitution of git://to https://

现在,就像魔法一样,所有 git 命令都将执行git://to的替换https://

source:git:// protocol blocked by company, how can I get around that?

来源:git:// 协议被公司阻止,我该如何解决?

回答by Isaque Elcio

inside the .ssh folder Create "config" file

在 .ssh 文件夹中创建“配置”文件

Host github.com
User git
Hostname ssh.github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
Port 443

Host gitlab.com
Hostname altssh.gitlab.com
User git
Port 443
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa

回答by kip2

Quick workaround: try switching to a different network

快速解决方法:尝试切换到不同的网络

I experienced this problem while on a hotspot (3/4G connection). Switching to a different connection (WiFi) resolved it, but it's just a workaround - I didn't get the chance to get to the bottom of the issue so the other answers might be more interesting to determine the underlying issue

我在热点(3/4G 连接)上遇到了这个问题。切换到不同的连接 (WiFi) 解决了它,但这只是一种解决方法 - 我没有机会深入问题的根源,因此其他答案可能更有趣以确定潜在问题

回答by Animesh Singh

I faced the same problem and couldn't find a working solution. I faced this problem while setting up a local server and the git couldn't connect through my proxy network but my workstation could. This was the output when I ran the command ssh -vT [email protected]

我遇到了同样的问题,找不到可行的解决方案。我在设置本地服务器时遇到了这个问题,git 无法通过我的代理网络连接,但我的工作站可以。这是我运行命令时的输出 ssh -vT [email protected]

ubuntu@server:~$ ssh -vT [email protected]
OpenSSH_7.2p2 Ubuntu-4ubuntu2.8, OpenSSL 1.0.2g  1 Mar 2016
debug1: Reading configuration data /home/ubuntu/.ssh/config
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to github.com [13.234.176.102] port 22.

So I tried using an SSH connection made over the HTTPS port by editing the config file ~/.ssh/configbut to no avail.

因此,我尝试通过编辑配置文件使用通过 HTTPS 端口建立的 SSH 连接, ~/.ssh/config但无济于事。

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

Finally, I found this articlewhich solved and exposed the real problem.

最后,我找到了这篇文章,它解决并暴露了真正的问题。

# github.com
Host github.com
    Hostname ssh.github.com
    ProxyCommand nc -X connect -x <PROXY-HOST>:<PORT> %h %p
    Port 443
    ServerAliveInterval 20
    User git

This is my config file and now git works perfectly well through ssh!

这是我的配置文件,现在 git 可以通过 ssh 完美运行!

回答by ameen

Execute:

执行:

nc -v -z <git-repository> <port>

Your output should look like:

您的输出应如下所示:

"Connection to <git-repository> <port> port [tcp/*] succeeded!"

If you get:

如果你得到:

connect to <git-repository> <port> (tcp) failed: Connection timed out

You need to edit your ~/.ssh/config file. Add something like the following:

您需要编辑您的 ~/.ssh/config 文件。添加如下内容:

Host example.com
Port 1234

回答by Artur Grigio

I was having this same issue, but the answer I found was different, thought someone might come across this issue, so here is my solution.

我遇到了同样的问题,但我发现的答案不同,认为有人可能会遇到这个问题,所以这是我的解决方案。

I had to whitelist 2 IPs for port 22, 80, 443, and 9418:

我不得不白名单2层的IP端口22804439418

  • 192.30.252.0/22

  • 185.199.108.0/22

  • 192.30.252.0/22

  • 185.199.108.0/22

In case these IP's don't work, it might be because they got updated, you can find the most current ones on this page.

如果这些 IP 不起作用,可能是因为它们更新了,您可以在此页面上找到最新的 IP 。

回答by aPurpleDev

I had this issue for 2 hours and it turns out removing the "s" from https and just do:

我遇到了这个问题 2 个小时,结果从 https 中删除了“s”,然后执行以下操作:

git clone -b <branchName> http:<projecturl>

git clone -b <branchName> http:<projecturl>

Fixed it.

修复。

回答by Shivaprasad R

ISSUE:Step to produce issue: git clone [email protected]:sramachand71/test.git for the first time in the new laptop ERRORssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository.

问题:产生问题的步骤: git clone [email protected]:sramachand71/test.git 首次在新笔记本电脑中出现 错误ssh:连接到主机 github.com 端口 22:连接超时致命:无法从远程读取存储库。

Please make sure you have the correct access rights and the repository exists. SOLUTIONfor the first time in the system to clone we need to give double quotes for the clone command. $ git clone "[email protected]:sramachand71/test.git" i face this issue in the system even after everything was correct but noticed at last that double quote is must for url "repository_url.git" for first time or new user in the system.

请确保您拥有正确的访问权限并且存储库存在。 SOLUTION第一次在系统中进行clone 我们需要给clone 命令双引号。$ git clone "[email protected]:sramachand71/test.git" 我在系统中遇到了这个问题,即使一切都是正确的,但最后注意到对于第一次或新用户的 url "repository_url.git" 必须使用双引号在系统中。