2

we have a git repository on remove server A. I normally access that via ssh from my work machine, e.g.

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

However, A is not accessible directly from outside work. 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. 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. Any suggestions how I can access A directly?

2 Answers 2

5

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.

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 clone user@A:/path/to/repo
Sign up to request clarification or add additional context in comments.

2 Comments

Great, thanks. A quick note to readers: commit using the standard syntax , e.g. "git commit -m ". Push by specifying the path to the wrapper: GIT_SSH='./ssh-wrapper.sh' git push
I needed to invoke ruby's bundler with a specific deploy key. After ages of searching I finally found the magic env variable in your answer. Thanks!
2

I think you want a SSH-Tunnel to make it through A. Take a look at this: http://www.revsys.com/writings/quicktips/ssh-tunnel.html

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.