Access Git repo via SSH tunnel

给你一囗甜甜゛ 提交于 2019-12-31 09:44:14

问题


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?


回答1:


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.



来源:https://stackoverflow.com/questions/16960567/access-git-repo-via-ssh-tunnel

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!