git - 如何设置 Corkscrew 通过 Draconian 代理连接到 Github

标签 git ssh proxy

我的公司有一个严苛的代理服务器,它阻止我通过 SSH 连接来删除服务器,从而阻止我使用 github。我花了最后一天时间在网络上关注示例,例如

但似乎没有任何效果。这是我的 ~/.ssh/config 文件:

ProxyCommand /usr/local/bin/corkscrew proxy02.COMPANY_NAME.com 8080 %h %p

Host github.com
User git
Port 22
Hostname github.com
IdentityFile "/Users/msnider/.ssh/id_rsa"
IdentitiesOnly yes
TCPKeepAlive yes

Host ssh.github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile "/Users/msnider/.ssh/id_rsa"
IdentitiesOnly yes
TCPKeepAlive yes

这是我在尝试 git pull --rebase 时收到的错误消息:

Proxy could not open connnection to github.com:  Forbidden
ssh_exchange_identification: Connection closed by remote host
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

当我尝试通过 SSH 连接到 github.com 时,我遇到了同样的禁止错误,但是如果我指定我的身份,我可以通过 ssh 连接到 ssh.github.com:

ssh -i ~/.ssh/id_rsa git@ssh.github.com
Hi mattsnider! You've successfully authenticated, but GitHub does not provide shell access.
Connection to ssh.github.com closed.

连接到代理服务器不需要身份验证。

我还尝试设置 http_proxyhttps_proxy 环境变量:

http_proxy=http://proxy02.COMPANY_NAME.com:8080
https_proxy=http://proxy02.COMPANY_NAME.com:8080

任何人都知道我做错了什么以及我如何才能让它发挥作用?谢谢。

最佳答案

我终于明白了。我公司的代理服务器阻止了除 80 和 443 以外的端口上的所有通信,因此我无法通过端口 22 连接到 github。我以为我在网上找到的示例是将通信从 22 更改为 443,但他们没有。

问题出在所有网络示例中的这部分代码:

Host github.com
User git
Port 22
Hostname github.com
IdentityFile "/Users/msnider/.ssh/id_rsa"
IdentitiesOnly yes
TCPKeepAlive yes

这表示从代理服务器连接到 github.com 时使用主机名 github.com 和端口 22,这被我的代理阻止了。通过将 github.com 定义更改为:

Host github.com
User git
Port 443
Hostname ssh.github.com
IdentityFile "/Users/msnider/.ssh/id_rsa"
IdentitiesOnly yes
TCPKeepAlive yes

我终于可以连接到github了。

关于git - 如何设置 Corkscrew 通过 Draconian 代理连接到 Github,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21318535/

相关文章:

git - 在 cygwin 中使用带有 xargs 的子字符串

linux - putty 端口转发 mysql windows

java - 你如何通过代理下载文件

来自其他本地用户的 git clone

git + 部署到生产环境

git - TFS 2018 将工作项与没有 pull 请求的提交相关联

c# - 如何使用 SSH 连接与 linux 服务器连接?

python - 使用远程容器Python解释器的PyCharm远程调试

java自动代​​理配置

dns - 当有 SOCKS 代理时,为什么我的脚本遵循/etc/hosts 但浏览器不遵循?