考虑到以下限制,我如何在 Windows 和 Unix 上使用 GitHub?

  • 所有对互联网的访问都仅限于代理
  • 代理仅允许端口 80 和 443 上的连接
  • CONNECT 方法仅对 443 启用
  • 需要代理身份验证(NTLM 或基本)
有帮助吗?

解决方案

看到 “通过严格的代理(Windows 和 Unix)使用 Github” 作者:Jeff Tchang(以前可从 另一个地点),其中包括适用于 Windows 和 Unix 平台的说明,总结如下。

Unix

  1. 下载 Git。
  2. 下载并安装 开瓶器.
  3. 编辑或创建文件 ~/.ssh/config 并输入以下内容:

    ProxyCommand /usr/bin/corkscrew proxy.example.com 443 %h %p ~/.ssh/myauth
    
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile "/media/truecrypt1/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile "/media/truecrypt1/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
  4. 如果一切设置正确,您应该能够运行 ssh github.com 并看到

    你好用户!您已成功通过身份验证,但 GitHub 不提供 shell 访问权限。
    与 github.com 的连接已关闭。

    如果这不起作用,你可以运行 ssh ssh.github.com 并得到完全相同的东西。如果第一个命令不起作用,则意味着您正在使用阻止端口 22 上的 CONNECT 的代理。几乎没有代理会阻止端口 443 上的 CONNECT,因为 SSL 需要它。

视窗

  1. 下载 系统管理工具. 。一些设置:
    • “从 Windows 命令提示符运行 Git”
    • “使用OpenSSH”(这个很重要)
    • 选择行结尾
  2. 下载 连接.c. 。这个工具值得拥有自己的位置,主要是因为它非常简单。它反映了开源工具 corkscrew,用于通过代理进行隧道传输。是的,该工具的名称确实称为“ Connect.C”。对于Windows用户,可以提供预编译的二进制文件。我把我的 connect.exeC:\Windows\connect.exe.
  3. 决定您是否喜欢使用 Windows cmd.exe 做一些事情或 Cygwin 风格的 shell。或两者。
  4. 设置 Cygwin Git bash shell。

    对于 Cygwin 风格的 shell,启动 Git 图标并编辑文件 ~/.ssh/config 并确保该文件没有扩展名。将以下内容放入该文件中,并注意如何指定路径。

    ProxyCommand /c/windows/connect.exe -H username@proxy.example.com:443 %h %p
    
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile "/c/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile "/c/Keys/GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
  5. 设置 Windows cmd.exe 壳。

    假设您不喜欢 Git Bash shell。您更喜欢 cmd.exe 解释器。

    • 转到您的配置文件 C:\Documents and Settings\.ssh\config
    • 复制一份或制作一份新的。我打电话给我的 config-windows

    将以下内容放入文件中,再次仔细注意路径分隔符和样式。

    ProxyCommand C:/Windows/connect.exe -H username@proxy.example.com:443 %h %p
    
    Host github.com
    User git
    Port 22
    Hostname github.com
    IdentityFile "C:\Keys\GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    
    Host ssh.github.com
    User git
    Port 443
    Hostname ssh.github.com
    IdentityFile "C:\Keys\GitHubKey.private"
    TCPKeepAlive yes
    IdentitiesOnly yes
    

有关完整详细信息,请参阅 完整的博客文章.

其他提示

[由于我对上面给出的第一个答案的补充在四天内没有获得批准,所以我将其放在这里。]

注意 corkscrewconnect, ,以及标准 Unix 命令 nc 仅支持基本身份验证(不安全地传输密码)。
tunnel-auth 版本0.04 此外还支持摘要身份验证。

如果您的代理需要 NTLM 身份验证,所有这些命令可以与 cntlm 如下:

选择一个本地端口(例如,如下例中的 8080) cntlm 将收听(使用代理执行用户身份验证并将任何其他软件包转发到代理),设置端口等。(例如,在/etc/cntlm.conf),并使用上面给出的 ProxyCommand 代替(插入相应的端口号):

ProxyCommand 开瓶器 127.0.0.1 8080 %h %p

或者

ProxyCommand connect -H 127.0.0.1:8080 %h %p

或者

ProxyCommand nc -X 连接 -x 127.0.0.1:8080 %h %p

或者

ProxyCommand 隧道验证 -p 127.0.0.1:8080 -r %h:%p

我的场景与 Jeff Tchang 的有点不同(但基于他的帖子),但在这里可能会有所帮助。

我们所有的工作场所/公司互联网访问都是通过非身份验证代理进行的。我能够克隆 但不推 github:跑步

git push -u origin master

会回来

ssh: connect to host github.com port 22: Operation timed out
fatal: The remote end hung up unexpectedly

基于 http://returnbooleantrue.blogspot.com/2009/06/using-github-through-draconian-proxies.htmlhttp://meinit.nl/ssh-through-a-proxy-from-your-apple-mac-os-xhttp://www.mtu.net/~engstrom/ssh-proxy.php 我能够下载/安装 corkscrew 并将以下内容添加到我的 ~/.ssh/config 中:

Host github.com
  User git
  Port 22
  Hostname github.com
  TCPKeepAlive yes
  IdentitiesOnly yes
  ProxyCommand /usr/local/bin/corkscrew proxy.<my-workplace>.com 8080 %h %p 

需要注意的几点:

  • 我也将我的工作场所/公司私钥用于 GitHub:如果不这样做,您将需要添加“IdentityFile”行

  • 与 Jeff Tchang 不同(感谢 mtu.net),我不需要在 ProxyCommand 行末尾添加“~/.ssh/myauth”

  • 我不需要设置 ssh.github.com 主机部分。

希望这些有帮助。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top