简体   繁体   English

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

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

I am under a proxy and I am pushing in to git successfully for quite a while.我在代理下,我成功地推入了 git 很长一段时间。
Now I am not able to push into git all of a sudden.现在我不能突然推入 git。
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.我已经设置了 RSA 密钥和代理并仔细检查了它们,但没有用,git 向我抛出页面标题中显示的错误。

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 ssh config (or add it if it does not exist).对我来说,我在我的 AWS EC2 UBUNTU 实例上遇到了这个错误,我解决它的方法是编辑 ssh 配置(或者如果它不存在则添加它)。

sudo nano ~/.ssh/config

And I added the following我添加了以下内容

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

Then, run the command ssh -T git@github.com to confirm if the issue is fixed.然后,运行命令ssh -T git@github.com以确认问题是否已解决。

According tothis 据此

Sometimes, firewalls refuse to allow SSH connections entirely.有时,防火墙完全拒绝允许 SSH 连接。 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.如果无法使用带有凭证缓存的 HTTPS 克隆,您可以尝试使用通过 HTTPS 端口建立的 SSH 连接进行克隆。 Most firewall rules should allow this, but proxy servers may interfere大多数防火墙规则应该允许这样做,但代理服务器可能会干扰

Hopefully this helps anyone else who's having the same issue I did.希望这可以帮助遇到与我相同问题的其他人。

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 git@github.com

this should timeout.这应该超时。 If that's the case use http protocol instead of ssh this way如果是这种情况,请以这种方式使用 http 协议而不是 ssh
just change your url in the config file to http.只需将配置文件中的 url 更改为 http。
Here is how :-方法如下:-

git config --local -e

change entry of更改条目

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

to

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

Basic URL Rewriting基本 URL 重写

Git provides a way to rewrite URLs using git config. Git 提供了一种使用 git config 重写 URL 的方法。 Simply issue the following command:只需发出以下命令:

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://https://的替换

source: git:// protocol blocked by company, how can I get around that?来源: git:// 协议被公司阻止,我该如何解决?

inside the .ssh folder Create "config" file在 .ssh 文件夹中创建“config”文件

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

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.我在设置本地服务器时遇到了这个问题,git 无法通过我的代理网络连接,但我的工作站可以。 This was the output when I ran the command ssh -vT git@github.com这是我运行命令ssh -vT git@github.com时的输出

ubuntu@server:~$ ssh -vT git@github.com
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/config but to no avail.因此,我尝试通过编辑配置文件~/.ssh/config来使用通过 HTTPS 端口建立的 SSH 连接,但无济于事。

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

Finally, I found this article which 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 运行良好!

Quick workaround: try switching to a different network快速解决方法:尝试切换到不同的网络

I experienced this problem while on a hotspot (3/4G connection).我在使用热点(3/4G 连接)时遇到了这个问题。 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切换到不同的连接 (WiFi) 解决了它,但这只是一种解决方法 - 我没有机会深入了解问题的根源,因此其他答案可能更有趣以确定潜在问题

For me, the problem was from ISP side.对我来说,问题出在 ISP 方面。 The Port number was not enabled by the Internet Service Provider. Internet 服务提供商未启用端口号。 So asked them to enable the port number over my network and it started working.所以要求他们通过我的网络启用端口号并开始工作。
Only to test: Connect to mobile hotspot and type ssh -T git@bitbucket.org or git pull.仅用于测试:连接到移动热点并输入ssh -T git@bitbucket.org or git pull.
If it works, then ask your ISP to enable the port.如果可行,请让您的 ISP 启用该端口。

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.您需要编辑 ~/.ssh/config 文件。 Add something like the following:添加如下内容:

Host example.com
Port 1234

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 :我必须将229418 443的 2 80 IP 列入白名单:

  • 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 不起作用,可能是因为它们已更新,您可以在此页面上找到最新的。

In a similar failure mode as Ludder, I was getting this error when I hadn't yet signed in to the correct company VPN.在与 Ludder 类似的故障模式中,当我还没有登录到正确的公司 VPN 时,我收到了这个错误。 :facepalm: :facepalm:

好的试试这个ssh -T -p 443 git@ssh.github.com而不是ssh -T git@github.com

The answer above gave me the information needed to resolve this issue.上面的答案为我提供了解决此问题所需的信息。 In my case the url was incorrectly starting with ssh:///在我的情况下,网址错误地以 ssh:/// 开头

To check the url in your git config is correct, open the git config file :-要检查 git config 中的 url 是否正确,请打开 git config 文件:-

git config --local -e

Check the url entry.检查 url 条目。 It should NOT have ssh:/// at the start.它不应该在开头有 ssh:///。

Incorrect entry:输入错误:

 url = ssh:///git@github.com:username/repo.git

Correct entry:正确输入:

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

If your url is correct, then the next step would be to try the answer above that suggests changing protocol to http.如果您的 url 是正确的,那么下一步将是尝试上面建议将协议更改为 http 的答案。

Changing the repo url from ssh to https is not very meaningful to me.将 repo url 从 ssh 更改为 https 对我来说意义不大。 As I prefer ssh over https because of some sort of extra benefits which I don't want to discard.因为我更喜欢ssh而不是https ,因为我不想放弃一些额外的好处。 Above answers are pretty good and accurate.上面的答案非常好和准确。 If you face this problem in GitLab, please go to their official documentation page and change your config file like that.如果您在 GitLab 中遇到此问题,请转到他们的官方文档页面并像这样更改您的配置文件。

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

Restart the computer solved it for me.重新启动计算机为我解决了它。
Git version: 2.27.0.windows.1 Git版本: 2.27.0.windows.1
OS version: Windows 10操作系统版本: Windows 10

The main reason was the change from the proxy installed by the company recently, which has blocked other ssh connections other than those to the company domain.主要原因是公司最近安装的代理发生了变化,它阻止了除公司域之外的其他ssh连接。

I was able to connect successfully by following these steps:我能够按照以下步骤成功连接:

  1. Double checked that the issue is what I am assuming by ssh -T git@github.com仔细检查问题是我假设的问题ssh -T git@github.com

It should end up in a timeout.它应该以超时结束。

  1. Edited the local remote URL by通过编辑本地远程 URL

ssh config --local -e

and from并从

url=git@github.com:asheeshjanghu/Journal.git

to

url=https://github.com/asheeshjanghu/Journal.git

The important point is that in the url you have to change at 2 places.重要的一点是,您必须在 url 中更改 2 个位置。

from git@ to https:// and from github:username to github/usernamegit@https://和从github:usernamegithub/username

In the end verify by doing a git fetch最后通过执行git fetch进行验证

In my case the problem was caused by a setting that I had changed on my Router a day before.就我而言,问题是由我前一天在路由器上更改的设置引起的。 So on my Router, I just had to revert the setting Isolation to disable and it has fixed my issue.所以在我的路由器上,我只需将设置恢复禁用,它就解决了我的问题。

在此处输入图像描述

My computer was unable to connect port 22 while connecting to Github.我的电脑在连接到 Github 时无法连接端口 22。 I never had this issue with bitbucket.我从来没有遇到过bitbucket的这个问题。 If you have both GitHub and bitbucket then如果您同时拥有 GitHub 和 bitbucket,那么

Host bitbucket.org
Hostname  altssh.bitbucket.org
Port  443


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

ref 参考

It basically connects SSH in 443 port instead of 22.它基本上在 443 端口而不是 22 端口连接 SSH。

This answer is based on the comment to the main question from @zundi (to whom credit should go, thanks zundi):这个答案基于@zundi 对主要问题的评论(应该归功于谁,谢谢 zundi):

  • Create a hotspot on your mobile device and connect to the hotspot在您的移动设备上创建一个热点并连接到该热点
  • git push
  • Turn off the hotspot on your mobile device and reconnect to the original network关闭移动设备上的热点并重新连接到原来的网络
  • git push continues to work git push继续工作

I do not know why temporarily connecting to a hotspot magically "kickstarts" the original network connection.我不知道为什么临时连接到热点会神奇地“启动”原始网络连接。

When I accidentally switched to a guest wifi network I got this error.当我不小心切换到访客wifi 网络时,我收到了这个错误。 Had to switch back to my default wifi network.不得不切换回我的默认wifi网络。

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>

Fixed it.解决它。

ISSUE: Step to produce issue: git clone git@github.com:sramachand71/test.git for the first time in the new laptop ERROR ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository. ISSUE:产生问题的步骤:git clone git@github.com:sramachand71/test.git 首次在新笔记本电脑中错误ssh:连接到主机 github.com 端口 22:连接超时致命:无法从远程读取存储库。

Please make sure you have the correct access rights and the repository exists.请确保您具有正确的访问权限并且存储库存在。 SOLUTION for the first time in the system to clone we need to give double quotes for the clone command. SOLUTION在系统中第一次克隆我们需要给克隆命令加上双引号。 $ git clone "git@github.com: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. $ git clone "git@github.com:sramachand71/test.git" 我在系统中遇到了这个问题,即使一切都正确,但最后注意到双引号对于第一次或新用户的 url "repository_url.git" 是必须的在系统中。

I had this issue on a server of mine that was set up with it's regular IP and a failover IP.我在使用常规 IP 和故障转移 IP 设置的服务器上遇到了这个问题。 The failover IP did not point to the server at this time.此时故障转移 IP 未指向服务器。 I had to remove the failover IP from the server configuration in /etc/netplan/01-netcfg.yaml .我不得不从/etc/netplan/01-netcfg.yaml中的服务器配置中删除故障转移 IP。 Pointing the failover IP to that server would have probably solved the issue as well.将故障转移 IP 指向该服务器可能也可以解决问题。

建议检查互联网连接或连接到另一个连接。

So I was having this same problem (not behind a proxy) and came across this question.所以我遇到了同样的问题(不是在代理后面)并且遇到了这个问题。 Here's what I did to fix it:这是我为修复它所做的:

Tried running ssh -T git@github.com and it did time out, but adding -o KexAlgorithms=ecdh-sha2-nistp521 made a successful connection (found from this answer to a semi-related question).尝试运行ssh -T git@github.com并确实超时,但添加-o KexAlgorithms=ecdh-sha2-nistp521建立了成功的连接(从this answer to a semi-related question中找到)。

To permanently fix this, I just added a line KexAlgorithms=ecdh-sha2-nistp521 under github.com in my ~/.ssh/config .为了永久解决这个问题,我刚刚在~/.ssh/configgithub.com下添加了一行KexAlgorithms=ecdh-sha2-nistp521 Everything seems to work fine now.现在一切似乎都很好。

如果您在 Windows 中,请移至存储 ssh 密钥的目录,然后重试,它对我有用。

What solved it for me was doing ssh-add on the key file.为我解决的是在密钥文件上执行ssh-add

ssh-add C:/Path/To/Key.pem

C:/Users/User/.ssh/config: C:/用户/用户/.ssh/config:

Host sshapp
    Hostname ssh.github.com
    IdentityFile C:/Path/To/Key.pem
    Port 443

Then clone using:然后克隆使用:

>git clone git@sshapp:<git_user>/app.git
Cloning into 'app'...
The authenticity of host '[ssh.github.com]:443 ([140.82.121.35]:443)' can't be established.
ED25519 key fingerprint is SHA256:+DiY3wvvV6T.....vCOqU.

刷新我的 Internet 连接和终端的 git reload功能对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 npm 安装错误:ssh:连接到主机 github.com 端口 22:连接超时 - npm install error: ssh: connect to host github.com port 22: Connection timed out 如何解决这个问题? ssh:连接到主机 github.com 端口 22:连接超时致命 - How to solve this? ssh: connect to host github.com port 22: Connection timed out fatal ssh:连接到主机 github.com 端口 22:连接超时致命:无法从远程存储库读取 - ssh: connect to host github.com port 22: Connection timed out fatal: Could not read from remote repository GitHub 错误 - “ssh:连接到主机 github.com 端口 22:操作超时致命:无法从远程存储库读取。” - GitHub Error - "ssh: connect to host github.com port 22: Operation timed out fatal: Could not read from remote repository." Github 连接到主机 github.com 端口 22:操作超时 - Github connect to host github.com port 22: Operation timed out `ssh:连接到主机 ssh.dev.azure.com 端口 22:连接超时`错误 - `ssh: connect to host ssh.dev.azure.com port 22: Connection timed out` error ssh:连接到主机端口 22:连接超时 - ssh: connect to host port 22: Connection timed out ssh:连接到主机git.ionicjs.com端口22:连接超时 - ssh: connect to host git.ionicjs.com port 22: Connection timed out ssh:连接到主机 gitlab.com 端口 22:连接超时 - ssh: connect to host gitlab.com port 22: Connection timed out ssh:连接到主机github.com端口22:将VM复制到另一台主机后,网络无法访问 - ssh: connect to host github.com port 22: Network is unreachable after copying VM to another host machine
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM