git 通过SSH隧道访问Git repo

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/16960567/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 16:20:50  来源:igfitidea点击:

Access Git repo via SSH tunnel

gitsshssh-tunnel

提问by Bootstrapper

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.

我可以访问一个可以访问 GIT 服务器的 SSH 帐户,并且能够在此 SSH 登录中克隆/推/拉存储库。但是我无法从其他地方访问这个 repo。

On the SSH account I use,

在我使用的 SSH 帐户上,

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,

我尝试使用从另一台机器设置到 git 服务器的 ssh 隧道,

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?

但是,我不断提示输入用户“git”的密码。任何想法我在这里做错了什么?

采纳答案by gcbenison

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.

一个 ssh 客户端在本地主机 ('sshserver') 上启动,并使用公钥身份验证与 'gitserver' 进行身份验证。如果系统提示您输入用户 'git' 的密码,则意味着公钥身份验证失败,ssh 将通过下一个方法,即密码身份验证。

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.

公钥认证失败的最可能原因是 ssh 客户端没有所需的私钥。我怀疑在这种情况下,作为“git@gitserver”进行身份验证所需的密钥驻留在 sshserver:~/.ssh 中,在这种情况下,当您尝试克隆存储库时,在本地主机上启动的 ssh 客户端将无法使用它通过您的 ssh 隧道。

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.

要解决此问题,您需要授予该客户端访问相应密钥的权限。您可以将其添加到本地 ~/.ssh 中,或者将其加载到 ssh 代理中。