【问题标题】:How do I use GitHub through harsh proxies?如何通过苛刻的代理使用 GitHub?
【发布时间】:2010-11-05 14:54:22
【问题描述】:

鉴于以下限制,我如何从 Windows 和 Unix 使用 GitHub?

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

【问题讨论】:

    标签: git github


    【解决方案1】:

    请参阅 Jeff Tchang 的 “Using Github Through Draconian Proxies (Windows And Unix)”(以前可从 another location 获得),其中包括 Windows 和 Unix 平台的说明,总结如下。

    Unix

    1. 下载 Git。
    2. 下载并安装corkscrew
    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. 下载msysgit。一些设置:
      • “从 Windows 命令提示符运行 Git”
      • “使用 OpenSSH”(这个很重要)
      • 选择行尾
    2. 下载connect.c。这个工具值得拥有自己的帖子,主要是因为它非常简单。它反映了开源工具 corkscrew 并用于通过代理进行隧道传输。是的,这个工具的名字真的叫做“connect.c”。对于 Windows 用户,可以使用预编译的二进制文件。我把我的connect.exe 放入C:\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 shell。

      假设你不喜欢 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
      

    详情请见the full blog post

    【讨论】:

    【解决方案2】:

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

    我们所有的工作场所/公司互联网访问都是通过非身份验证代理。我能够克隆 from 但不能将 推送到 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 主机部分。

    希望这些帮助。

    【讨论】:

      【解决方案3】:

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

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

      如果您的代理需要 NTLM 身份验证,所有这些命令都可以很好地与cntlm 结合使用,如下所示:

      选择cntlm 将侦听的本地端口(例如,以下示例中的 8080) (使用代理执行用户身份验证并转发任何 进出代理的更多包),设置端口等(例如,在 /etc/cntlm.conf),并使用而不是上面给出的 ProxyCommand(插入相应的端口号):

      ProxyCommand 开瓶器 127.0.0.1 8080 %h %p

      ProxyCommand 连接 -H 127.0.0.1:8080 %h %p

      ProxyCommand nc -X connect -x 127.0.0.1:8080 %h %p

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

      【讨论】:

        猜你喜欢
        • 2021-01-14
        • 1970-01-01
        • 1970-01-01
        • 2011-07-09
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多