如果您想解决证书问题,可以跳过此答案。这个答案涉及到通过防火墙隧道化SSH的方法,相比于使用防火墙/代理更加好用。
有一种比使用HTTP访问更好的方式,那就是在ssh.github.com服务器的443端口上使用GitHub提供的SSH服务。
我们使用一个叫做Corkscrew的工具。它适用于Cygwin(通过从Cygwin主页安装)和Linux(使用你喜欢的打包工具)。对于Mac OS X,至少可从MacPorts和Homebrew(可执行文件brew
)中获取。
命令行如下:
corkscrew <proxyhost> <proxyport> <targethost> <targetport> <authfile>
proxyhost和proxyport是HTTPS代理的坐标。 targethost和targetport是要隧道连接到的主机的位置。 authfile是一个文本文件,其中一行包含用冒号分隔的代理服务器用户名/密码。
E.g.:
abc:very_secret
使用“普通”SSH协议进行Git通信的安装。
通过将此内容添加到〜/ .ssh / config
中,可以将此技巧用于普通SSH连接。
Host github.com
HostName ssh.github.com
Port 443
User git
ProxyCommand corkscrew <proxyhost> <proxyport> %h %p ~/.ssh/proxy_auth
现在你可以通过ssh连接到gitproxy来测试它是否正常工作:
ssh github.com
输出:
PTY allocation request failed on channel 0
Hi ptillemans! You've successfully authenticated, but GitHub does not provide shell access.
Connection to github.com closed.
(备注:如果您之前从未登录过GitHub,则 ssh
将会要求将服务器密钥添加到已知主机文件中。如果您是多疑的,建议验证RSA指纹是否与上传密钥的GitHub网站上显示的一致)。
稍有变化的方法是当您需要使用另一个密钥访问存储库时,例如,将您的私人账户与您的专业账户分开。
# Account dedicated for the ACME private GitHub account
#
Host acme.github.com
User git
HostName ssh.github.com
Port 443
ProxyCommand corkscrew <proxyhost> <3128> %h %p ~/.ssh/proxy_auth
IdentityFile ~/.ssh/id_dsa_acme
享受吧!
我们多年来一直在Linux、Mac和Windows上使用它。
如果您想了解更多信息,可以在此博客文章中阅读更多内容。