Reputation: 1842
I have: local, server1, server2.
I have Git repository on server2. But I can't connect with it. I can connect to server1 with SSH and then connect to server2 with SSH.
How can I push commits to server2 with double SSH? Is it possible?
Upvotes: 7
Views: 1840
Reputation: 1977
Have a look at ssh's ProxyCommand. By adding a section into your ssh config file like
Host server2
ProxyCommand ssh -q server1 nc -q0 %h 22
you should be able to use git with a repo an server2. Note: This requires nc being available on server1.
This solution makes accessing server2 through ssh, e.g. with git, transparent as if it was directly accessible.
Upvotes: 6
Reputation: 323434
One solution is to prepare SSH tunnel on gateway host (server1), and use Git with the local end (you might need to use .ssh/options
to configure port).
Another is a pure Git solution to use ext::
remote helper with double SSH (you better set up password-less public key based authentication at least on gateway, or you would have to give passwords twice). For example:
local ~$ git clone \
"ext::ssh -t user@server1 ssh server2 %S 'repo'" repo
Cloning into 'repo'...
Checking connectivity... done.
Here %S
will be expanded by Git into full name of appropriate service, git-upload-pack
for fetching and git-receive-pack
for push. The -t
option is needed if logging to internal host uses interactive authentication (e.g. password).
Note that you need to give the name or directory to download to as the last parameter to git clone
command (repo
here) to the resulting repository here; otherwise Git would use the command (ssh ...
) as name.
Then you would be able to fetch and push to repository by the name "origin".
Upvotes: 7