Git remote add through 2 ssh servers

Viewed 48

Using Git, how can I add a remote from my local machine to a virtual machine (for hosting) that is only accessible from a secondary machine?

So to access this machine I would normally have to ssh into the first, then ssh into the second from the first one.

Is there a way to git remote add prod ssh://user@server1.co.uk > ssh://user@server2.co.uk/app-deployment.git from my local machine?

Or will I have to set up another remote in the middle server with more hooks?

EDIT: The working repository is on my local machine, but the --bare repository I want to add as a remote is on "server2", there's no repository or code on server1, but I can only reach "server2" through ssh from "server1".

2 Answers

try this:

git remote add origin <user>@<remote-server>:/absolute/path/to/repistory

Use server1 as an SSH jump host. On your local machine edit ~/.ssh/config and add

Host server2
    ProxyJump user1@server1
    User user2

Test the configuration: from the local machine try

ssh server2

or

ssh user2@server2

If SSH successfully connects to server2 "directly" from your local machine (not really directly but automatically connecting to server1 and using it as a proxy) add it as a remote in Git repo:

git remote add prod ssh://user2@server2/repo.git
Related