通过防火墙后面的ssh访问git存储库

paj*_*to0 13 git proxy openssh jsch

我想访问(克隆/推/拉)私有(通过ssh)git存储库,而后面只允许http代理访问的企业防火墙.我编写了一个强大的Java(守护程序)程序(基于JSCh类库),这将允许我利用本地和远程端口转发,我希望利用这一点,但当我试图设想如何设置时,我的大脑会受伤.

git repo depot(硬币短语)位于foo.server.com/var/git,因此设置克隆的自然倾向,忽略了fireall,将是:

$ git clone ssh://foo.server.com/var/git/myrepo.git
Run Code Online (Sandbox Code Playgroud)

但防火墙会阻止此命令.我倾向于尝试类似的东西

$ git clone ssh://localhost:8022/var/git/myrepo.git
Run Code Online (Sandbox Code Playgroud)

localhost:8022转发到foo.server.com:22

这条道路值得追求吗?有没有更安全的解决方案?我应该注意哪些陷阱或陷阱?

小智 31

使用socat.ssh/config这样:

Host=foo.server.com
ProxyCommand=socat - PROXY:your.proxy.ip:%h:%p,proxyport=3128,proxyauth=user:pwd
Run Code Online (Sandbox Code Playgroud)

您应该能够sshfoo.server.com

git clone ssh://foo.server.com/var/git/myrepo.git
Run Code Online (Sandbox Code Playgroud)

预计会奏效.

  • 很好,这是这个烦人问题的最终解决方案.真棒![关于此的小帖子](http://albertgroothedde.com/post/2017-04-fix-ssh-and-git-clone-behind-proxy-on-macos/) (2认同)

Thi*_*ilo 8

你能得到正常的ssh(命令行)会话吗?如果是这样,git也应该工作.

使用ssh时,git应该在.ssh/config中选择配置选项.如果这还不够,可以将环境变量GIT_SSH指向ssh(或shell脚本包装器)的修改版本.

  • 不,这就是让这么难的原因.只允许http通过防火墙.我可以使用SSH配置黑客来获得正常的ssh命令,但我不相信这些会对git命令有所帮助.我很想听到我错了,当我上班的时候我会尝试这个. (3认同)
  • 当然.我设置了GIT_SSH = sshx,其中sshx是我的PATH变量上的一个命令,它指定一个使用corkscrew绕过防火墙的配置文件,即sshx是"ssh -F~/path/to/xconfig $*"并且xconfig包含(在Host下)*)"ProxyCommand corkscrew proxy-host.foo.com 80%h%p/path/to/proxyauth" (2认同)

INS*_*INS 6

这是我在 Linux 机器下运行的设置(端口 18081 上的本地主机是代理)。

cat ~/.ssh/config
Host  github.com
  User git
  ProxyCommand nc -x localhost:18081 -Xconnect %h %p
Run Code Online (Sandbox Code Playgroud)