Git with double SSH

前端 未结 2 1615
忘掉有多难
忘掉有多难 2020-12-19 19:38

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 S

相关标签:
2条回答
  • 2020-12-19 19:53

    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.

    0 讨论(0)
  • 2020-12-19 19:54

    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".

    0 讨论(0)
提交回复
热议问题