【发布时间】:2010-11-05 14:54:22
【问题描述】:
鉴于以下限制,我如何从 Windows 和 Unix 使用 GitHub?
- 所有对 Internet 的访问都仅限于代理
- 代理只允许端口 80 和 443 上的连接
- CONNECT 方法仅对 443 启用
- 需要代理身份验证(NTLM 或基本)
【问题讨论】:
鉴于以下限制,我如何从 Windows 和 Unix 使用 GitHub?
【问题讨论】:
请参阅 Jeff Tchang 的 “Using Github Through Draconian Proxies (Windows And Unix)”(以前可从 another location 获得),其中包括 Windows 和 Unix 平台的说明,总结如下。
编辑或创建文件~/.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
如果一切设置正确,您应该能够运行ssh github.com 并查看
用户好!您已成功通过身份验证,但 GitHub 不提供 shell 访问权限。
与 github.com 的连接已关闭。
如果这不起作用,您可以运行 ssh ssh.github.com 并得到完全相同的结果。如果第一个命令不起作用,则意味着您使用的代理阻止了端口 22 上的 CONNECT。几乎没有代理阻止端口 443 上的 CONNECT,因为 SSL 需要它。
connect.exe 放入C:\Windows\connect.exe。cmd.exe 来做事还是使用 Cygwin 风格的 shell。或两者兼而有之。设置 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
设置 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。
【讨论】:
connect.exe 作为 msysgit 的一部分安装。它被包含在February of 2010。
我的场景与 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.html 和 http://meinit.nl/ssh-through-a-proxy-from-your-apple-mac-os-x 和 http://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 主机部分。
希望这些帮助。
【讨论】:
[由于我对上面给出的第一个答案的补充在四天内没有得到批准,所以我把它放在这里。]
请注意corkscrew 和connect,以及标准的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
【讨论】: