需要在防火墙后面使用 git:尝试 ssh 隧道
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2533015/
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
need to use git behind firewall: trying ssh tunneling
提问by Hymano
I am trying to use ssh port forwarding to defeat corporate firewall:
我正在尝试使用 ssh 端口转发来击败企业防火墙:
ssh git@GIT_SERVER -L9418:GIT_SERVER:9418
and in another terminal I run
在另一个终端我运行
git clone git://localhost:repositories/project.git
But I get the following error:
但我收到以下错误:
Initialized empty Git repository in /Users/aboxer/tmp/glucosia/.git/
fatal: Unable to look up localhost (port repositories) (nodename nor servname provided, or not known)
在 /Users/aboxer/tmp/glucosia/.git/ 中初始化空 Git 存储库
致命:无法查找本地主机(端口存储库)(提供节点名或服务名,或未知)
Thanks!
谢谢!
采纳答案by Cascabel
I'm pretty sure your problem (or at least the one causing this particular error) is here:
我很确定您的问题(或至少是导致此特定错误的问题)在这里:
git clone git://localhost:repositories/project.git
If you look at the list of url notationsin man git push you'll see the relevant example:
如果您查看man git push中的 url 符号列表,您将看到相关示例:
git://host.xz[:port]/path/to/repo.git/
With the colon, you're using "repositories" as the port name, and git (understandably) has trouble connecting to port repositories on local host! What you're looking for is:
使用冒号,您使用“存储库”作为端口名称,而 git(可以理解)无法连接到本地主机上的端口存储库!你要找的是:
git://localhost/path/to/repositories/project.git
or perhaps
也许
git://localhost/~user/repositories/project.git
Edit:
编辑:
I probably should've said this from the start, but I can't actually think of a reason you'd need to use SSH tunneling with git. Its default transport protocol is ssh; the git protocol is really only present to allow public repositories to be fetched from without an account. If you can SSH into the machine where the repository is located, you can just fetch via ssh:
我可能应该从一开始就这么说,但我实际上想不出您需要将 SSH 隧道与 git 一起使用的原因。它的默认传输协议是 ssh;git 协议实际上只是为了允许在没有帐户的情况下获取公共存储库。如果您可以通过 SSH 连接到存储库所在的机器,则可以通过 ssh 获取:
git clone ssh://[user@]host.xz/path/to/repo.git
git clone ssh://[user@]host.xz/~/path/to/repo.git
git clone ssh://[user@]host.xz/~user/path/to/repo.git
回答by Vlad Zloteanu
I wrote a complete response/guide here: http://vladzloteanu.wordpress.com/2010/12/18/git-through-ssh-port-forwarding-ssh-tunneling/.
我在这里写了一个完整的回复/指南:http: //vladzloteanu.wordpress.com/2010/12/18/git-through-ssh-port-forwarding-ssh-tunneling/。
回答by Pylinux
The short version of Vlad Zloteanu's answer:
Vlad Zloteanu 回答的简短版本:
Set up the tunnel:
设置隧道:
ssh ServerWithSSHAccessAddress -L 2000:GitServerAddress:22 -N , &
Clone the repo
克隆回购
git clone ssh://user@localhost:2000/my_repo.git
回答by lucas
Here are the steps that worked for me. My system is behind company firewall and it is domain joined:
以下是对我有用的步骤。我的系统位于公司防火墙后面,并且已加入域:
- First npm needs to be installed
- Fiddler needs to be in running mode as well. Fiddler needs to be running with ‘Automatically Authenticate' option under ‘Rules' enabled
- Install Git via command:
- 首先需要安装npm
- Fiddler 也需要处于运行模式。Fiddler 需要在启用“规则”下的“自动验证”选项的情况下运行
- 通过命令安装 Git:
npm install git
npm 安装 git
- Update protocol from git to https:
- 将协议从 git 更新为 https:
git config --global url.https://github.com/.insteadOfgit://github.com/
git config --global url。https://github.com/.insteadOfgit://github.com/