git 可以通过 ssh 端口转发工作吗?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/733057/
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 06:19:07  来源:igfitidea点击:

Can git work via ssh port forwarding?

gitssh

提问by okidogi

My situation is, I can ssh to ComputerB (Code repos) where git repos is put. But my local connection is too slow to clone the code. And I can ssh to another machine (ComputerA) which is faster, so I want to clone the code through ComputerA.

我的情况是,我可以通过 ssh 连接到放置 git repos 的 ComputerB(代码存储库)。但是我的本地连接速度太慢,无法克隆代码。我可以通过 ssh 连接到另一台更快的机器(ComputerA),所以我想通过 ComputerA 克隆代码。

This is what I did:

这就是我所做的:

           ssh tunnel                           ssh tunnel
MyComputer ----------> ComputerA (I can ssh to) ----------> ComputerB (where the Code repos is and I can ssh to but too slow)

Using a command like this:

使用这样的命令:

ssh -L1234:ComputerA_ip:22 Code_repos_ip

Then:

然后:

git clone git+ssh//localhost/repos local_repos (how can I assign the port 1234?)

If this doesn't work, what else can I do?

如果这不起作用,我还能做什么?

回答by Brian Campbell

How will going through two connections make your connection faster?

如何通过两个连接使您的连接更快?

Anyhow, you should be able to do:

无论如何,你应该能够做到:

git clone git+ssh://localhost:1234/repos local_repos

回答by Alexander Artemenko

Also, you can try to put port number in your ~/.ssh/config:

此外,您可以尝试将端口号放入您的~/.ssh/config

Host ComputerA
HostName localhost
Port 1234

And then use ComputerA in git clone command:

然后在 git clone 命令中使用 ComputerA:

git clone git+ssh://ComputerA/repos local_repos

回答by sybreon

Check out the command files for SSH. You can have a command automatically execute when you log in via SSH. This is specified in the authorized_keys file. So, on Computer A, you will have a command file that automatically SSH-es into Computer B. Then when you connect to Computer A, it will do it automatically to Computer B. To your computer, it is directly connected to Computer B. You can even use a compressed tunnel.

查看 SSH 的命令文件。您可以在通过 SSH 登录时自动执行命令。这是在authorized_keys 文件中指定的。因此,在计算机 A 上,您将有一个命令文件,该文件会自动将 SSH-es 连接到计算机 B。然后当您连接到计算机 A 时,它会自动执行到计算机 B。对于您的计算机,它直接连接到计算机 B。您甚至可以使用压缩隧道。

回答by JesperE

First clone to ComputerA, then clone from ComputerA to ComputerB. You'll have to ssh to ComputerA in order to pull in new stuff, though.

首先克隆到ComputerA,然后从ComputerA 克隆到ComputerB。不过,您必须通过 ssh 连接到 ComputerA 才能获取新内容。