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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1728934/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 07:20:32  来源:igfitidea点击:

Accessing a git repository via ssh behind a firewall

gitproxyopensshjsch

提问by pajato0

I would like to access (clone/push/pull) a private (via ssh) git repository while behind a corporate firewall that only allows http proxy access. I have written a robust Java (daemon) program (based on the JSCh class library) that will allow me to leverage local and remote port forwarding and I am hoping to leverage this but my brain hurts when I try to envision how to set this up.

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

The git repo depot (to coin a phrase) is at foo.server.com/var/git so the natural inclination, ignoring the fireall, to set up a clone would be:

git repo depot(创造一个短语)位于 foo.server.com/var/git 所以自然倾向,忽略fireall,设置一个克隆是:

$ git clone ssh://foo.server.com/var/git/myrepo.git

but the firewall will block this command. I'm inclined to try something like

但是防火墙会阻止这个命令。我倾向于尝试类似的东西

$ git clone ssh://localhost:8022/var/git/myrepo.git

where localhost:8022 is forwarded to foo.server.com:22

其中 localhost:8022 被转发到 foo.server.com:22

So is this path worth pursuing? Is there any easier solution that is still secure? Are there pitfalls or gotchas I should be aware of?

那么这条路值得走吗?是否有任何更简单的解决方案仍然安全?是否有我应该注意的陷阱或陷阱?

采纳答案by Thilo

Can you get a normal ssh (command-line) session going? If so, git should also work.

您可以进行正常的 ssh(命令行)会话吗?如果是这样,git 也应该工作。

When using ssh, git should pick up your configuration options in .ssh/config. If that is not enough, you can point the environment variable GIT_SSH at a modified version of ssh (or shell script wrapper).

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

回答by Gregor Beck

Using socatand a .ssh/configlike this:

使用socat.ssh/config这样的:

Host=foo.server.com
ProxyCommand=socat - PROXY:your.proxy.ip:%h:%p,proxyport=3128,proxyauth=user:pwd

You should be able to sshto foo.server.comand

您应该能够sshfoo.server.com

git clone ssh://foo.server.com/var/git/myrepo.git

is expected to work.

预计工作。