简体   繁体   English

使用ssh链从远程服务器克隆git

[英]git clone from remote server with ssh chaining

we have a git repository on remove server A. I normally access that via ssh from my work machine, eg 我们在删除服务器A上有一个git存储库。通常我从工作机上通过ssh访问该存储库,例如

git clone user@A:/path/to/repo

However, A is not accessible directly from outside work. 但是,不能直接从外部工作访问A。 There is another server, B, which I ssh into, which can then ssh into A. What I want to do now is to clone the repository on my machine at home. 我还有另一台服务器B,可以将它SSH到A中。我现在想要做的是在家里的机器上克隆存储库。 I tried stuff like 我尝试过类似的东西

git clone B:A:/path/to/repo
git clone user@B:A/path/to/repo

neither of which worked. 两者都不起作用。 I suppose I could copy the repo on B and clone from there, but merging changes back to A would be a hassle. 我想我可以在B上复制回购并从那里克隆,但是将更改合并回A会很麻烦。 Any suggestions how I can access A directly? 有什么建议可以直接访问A吗?

If you have passwordless SSH setup between server A and server B, then you can write a simple wrapper script which connects to server A via SSH and runs the command SSH with the arguments from Git. 如果在服务器A和服务器B之间设置了无密码的SSH,则可以编写一个简单的包装脚本,该脚本通过SSH连接到服务器A,并使用来自Git的参数运行命令SSH。

Create Script: 创建脚本:

cat << EOF > ssh-wrapper.sh
#!/bin/sh
ssh -T serverB.example.com ssh ${@}
exit $?
EOF
chmod 755 ssh-wrapper.sh

Then set GIT_SSH to ./ssh-wrapper.sh and call Git: 然后将GIT_SSH设置为./ssh-wrapper.sh并调用Git:

GIT_SSH='./ssh-wrapper.sh' git clone user@A:/path/to/repo

我认为您希望通过A的SSH隧道。请看一下: http : //www.revsys.com/writings/quicktips/ssh-tunnel.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM