Home > Enterprise >  How do I access a remote (local gitlab instance on remote server) repository over SSH?
How do I access a remote (local gitlab instance on remote server) repository over SSH?

Time:10-25

The setup is as follows:

  • remote private server far far away
  • remote private server has private gitlab instance on port XXXX
  • remote private server is configured to allow SSH sign-on via SSH key
  • gitlab instance on port XXXX of remote private server requires SSH key authentication using different SSH key

How can I clone that repository onto my local machine, and push/pull data remotely given that setup?

This is how I access it locally when I am not far, far away from remote private server:

git clone [email protected]:REPODIR/repo_name.git

In this case, XXX.XXX.XX.X is the IP of the local git-lab instance on the remote network.

Is there anyway to tunnel into the remote network and access the gitlab instance by proxy (forgive me for using the word wrong likely).

Thank you.

CodePudding user response:

Ok, mostly thanks to @o11c for this, although here are my findings that led me to be able to clone my repo remotely.

Disclaimer: ProxyJump (-J see ssh manpage) is the shorthand, more modern, version of this but I couldn't get it working -- if anyone wants to update with their implementation of ProxyJump that would be useful!

SSH into your remote account to the main server with port to your gitlab or other application instance, using your main identity (this can be in ~/.ssh or you can manually reference it with -i)

ssh -ND 3131 [email protected] -i ../../keys/XXX-ssh &

I then source this bash script in the shell I intend to run git commands (notice the ProxyCommand usage instead of ProxyJump, this is the old method of doing this yet it works well for me. also notice the 127.0.0.1:PORT should be swapped with your application's port)

alias ssh="ssh -o ProxyCommand='/usr/bin/nc -X 4 -x 127.0.0.1:3131 %h %p'"
export GIT_SSH=~/Desktop/XXX-eng/ssh-access/ssh-proxy.sh
export PRE_SSH_ALIAS_PROMPT="$PS1"
export PS1="<< SSH ALIAS >>$PS1"

Where ssh-proxy.sh is defined as follows: (again, swap the port out for your application, and possibly use ProxyJump if want modern implementation)

ssh -o ProxyCommand='/usr/bin/nc -X 4 -x 127.0.0.1:3131 %h %p' "$@"

Then, you can clone normally using:

git clone [email protected]:REPODIR/repo_name.git
  • Related