Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Access Git repo via SSH tunnel

I have access to an SSH account that can access a GIT server and am able to clone/push/pull the repo in this SSH login. However I cannot access this repo from elsewhere.

On the SSH account I use,

git clone git@gitserver:proj/myrepo.git

to clone the repo.

I tried setting up a ssh tunnel to the git server from another machine using,

ssh -L 3333:gitserver:22 userid@sshserver
git clone ssh://localhost:3333/proj/repo.git

However I keep getting prompted for a password for the user 'git'. Any ideas what I am doing wrong here?

like image 429
Bootstrapper Avatar asked Jun 06 '13 11:06

Bootstrapper


People also ask

How do I access SSH repository?

Steps to connect GitHub to SSH :Open the GitHub website and log in to your account. Go to the settings page from the menu in top right corner. Select “SSH and GPG keys” from the sidebar and click on “New SSH key” option. Add relevant title in the “Title” field and paste the SSH key in the “Key field“.

Does Git work over SSH?

Git can use four distinct protocols to transfer data: Local, HTTP, Secure Shell (SSH) and Git.


1 Answers

When you do this:

git clone git@gitserver:proj/myrepo.git

an ssh client is starting on the local host ('sshserver') and authenticating with 'gitserver' using public key authentication. If you get prompted for a password for user 'git', that means public key authentication has failed, and ssh is falling through to the next method, which is password authentication.

The most likely reason that public key authentication would fail is that the ssh client does not have the private key needed. I suspect in this case that the key needed to authenticate as 'git@gitserver' resides in sshserver:~/.ssh, in which case it would not be available to the ssh client started on your local host when you try to clone the repo through your ssh tunnel.

To solve this, you need to give that client access to the appropriate key. You could add it to ~/.ssh locally, or load it into an ssh agent.

like image 60
gcbenison Avatar answered Sep 18 '22 07:09

gcbenison