简体   繁体   English

无法通过 SSH 连接到 GitHub(但可以连接到 GitLab)

[英]Cannot connect to GitHub via SSH (But can connect to GitLab)

I've scoured the inte.net and found many people with similar problems, but my variant seems to be unique.我搜索了 inte.net,发现很多人都有类似的问题,但我的变体似乎是独一无二的。 The issue is I cannot connect to GitHub via ssh in order to push/pull (I'm on Windows 10).问题是我无法通过 ssh 连接到 GitHub 以进行推/拉(我在 Windows 10)。

If I run ssh -T git@github.com :如果我运行ssh -T git@github.com

ssh: connect to host github.com port 22: Network is unreachable

If I run ssh -T -p 443 git@github.com :如果我运行ssh -T -p 443 git@github.com

Hi cjriches! You've successfully authenticated, but GitHub does not provide shell access.

Bizarrely, if I run ssh -T git@gitlab.com :奇怪的是,如果我运行ssh -T git@gitlab.com

Welcome to GitLab, @cjriches!

This, combined with the fact that I tried disabling Windows Firewall to no avail, seems to prove that it's not just port 22 that's the problem.这与我尝试禁用 Windows 防火墙无济于事的事实相结合,似乎证明问题不仅仅是端口 22。 For what it's worth, I can also SSH into other, completely non-git-related hosts.对于它的价值,我还可以 SSH 进入其他完全与 git 无关的主机。 For some reason, it's GitHub specifically that refuses to connect.出于某种原因,具体是 GitHub 拒绝连接。 I've re-uploaded the public key just in case, so the problem definitely isn't there.为了以防万一,我已经重新上传了公钥,所以问题肯定不存在。

Has anybody got any ideas how on earth this could be happening?有没有人知道这到底是怎么发生的?

Seems like it is either a DNS issue or a Proxy issue.似乎是 DNS 问题或代理问题。 I would try changing my dns to 8.8.8.8 and 8.8.4.4.我会尝试将我的 dns 更改为 8.8.8.8 和 8.8.4.4。 See if that clears up the issue.看看这是否解决了问题。 If that still doesn't rectify the issue, I would look and see if I am using a proxy which is preventing me from contacting github.如果这仍然不能解决问题,我会查看我是否使用了阻止我联系 github 的代理。

I had the same issue.我遇到过同样的问题。 Solve it by disabling the Virus Safe and Child Safe in the "Manage my Web Safe settings" section in the virgin broadband account page.通过在原始宽带帐户页面的“管理我的网络安全设置”部分中禁用病毒安全和儿童安全来解决它。

Source: https://community.virginmedia.com/t5/Forum-Archive/GitHub-inaccesible-over-SSH/td-p/3816287来源: https : //community.virginmedia.com/t5/Forum-Archive/GitHub-inaccesible-over-SSH/td-p/3816287

Thanks to the OP and the other answers.感谢 OP 和其他答案。 My solution was to edit my ~/.ssh/config file (on linux).我的解决方案是编辑我的~/.ssh/config file (在 Linux 上)。

Host github.com
HostName 140.82.121.4
User git
AddKeysToAgent yes
# Linux does not recognise UseKeychain but Mac does
IgnoreUnknown UseKeychain 
UseKeychain yes
IdentityFile ~/.ssh/your_ssh_key_file

Check git config --show-origin -l to see if there is any setting (proxy or others) that might apply to github.com specifically.检查git config --show-origin -l以查看是否有任何可能专门适用于 github.com 的设置(代理或其他)。

And check your environment variables (' set ' in a CMD in Windows), also to double-check if any of those variables might involves GitHub.并检查您的环境变量(Windows 中 CMD 中的“ set ”),还要仔细检查这些变量中是否有任何可能涉及 GitHub。

My solution was to enable SSH connections over HTTPS. See GitHub docs for more information.我的解决方案是通过 HTTPS 启用 SSH 连接。有关更多信息,请参阅GitHub 文档

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM