问题
I'd like to clone a git repository from my company's servers to my personal computer. The only way to acces these servers from "outside" is by logging in per ssh to 'machine1'
ssh user@machine1.company.xy
Unfortunately, git ist not installed on that specific machine. So a git clone like
git clone ssh://user@machine1.company.xy/path/to/repo <local-repo-path>
won't work. What I would have to do is to change to another machine 'machine2' where git is installed after having logged in to the network via 'machine1'. So to get the clone working I would have to execute a command like
ssh machine2
before actually executing the git command. Is there any way to do that? Something like a pre-clone hook maybe?
Is it possible to somehow pack the remote repository into a file (patch?), to copy that file onto the local machine and to clone from that file?
Looking forward to your hints and suggestions!
回答1:
You can do this by configuring a ssh proxy command. Note: this assumes netcat is available on the proxy server; you can replace netcat with a similar script in perl or whatever if needed.
Add the following to your ~/.ssh/config
, creating it if needed:
Host machine1
User yourusername
HostName machine1.yourcompany.com
Host machine2
User yourusername
ProxyCommand ssh machine1 nc %h %p
HostName machine2.internal.network
Now you can ssh machine2
and it will automatically tunnel through machine1. This means using git is as simple as git clone ssh://machine2/path
.
It is also possible to bundle the repository into a single file, using the git bundle command. This shouldn't be necessary with a proper ssh proxy setup though.
来源:https://stackoverflow.com/questions/4769986/git-clone-from-remote-ssh-repository-change-the-machine-on-the-remote-network