使用Visual Studio 2017使用SSH连接到Git存储库 [英] Connect to Git repository with SSH using Visual Studio 2017

查看:2325
本文介绍了使用Visual Studio 2017使用SSH连接到Git存储库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Visual Studio 2017中的SSH连接到Git存储库(在Bitbucket上)(据我所知,它支持SSH for Git)。我已经设置了一切,存储库克隆在我的计算机上,并且我可以提交,但是如果我尝试执行类似于下面的消息(从Visual Studio的输出窗口)获取它的操作失败:

 获取时遇到的错误:Git失败并出现致命错误。 
致命:无法从远程存储库读取。

尝试从命令提示符处获得这些稍微更丰富的消息:

 权限被拒绝(publickey)。 
致命:无法从远程存储库读取。

请确保您拥有正确的访问权限
并存在存储库。

从Git Bash我尝试打开SSH代理,添加我的私钥和提取,似乎工作(或至少我没有得到任何消息,不像代理没有启动或没有添加密钥时):

  eval`ssh-agent` 
ssh-add〜/ .ssh / xxxx
git fetch

但是Visual Studio仍然无法连接。我也尝试在Windows命令提示符下做同样的事情:

  ssh-agent 
set SSH_AUTH_SOCK = / tmp /ssh-SIAryCa61iz9/agent.11128
set SSH_AGENT_PID = 9804
ssh-add xxxx
git fetch

但我仍然得到相同的错误。

我已经将公钥添加到Bitbucket,并且 ssh - T git@bitbucket.org 输出以xxxx登录。另外,我可以使用SourceTree正确连接,并将私钥添加到Pageant(我用于 ssh-add 的密钥具有所需的OpenSSH格式,我使用.ppk创建了它我最终设法使用PuTTY的Pageant身份验证代理而不是 ssh来运行它。 -agent ,然后按照这里(它适用于Visual Studio Code,但适用于Visual Studio 2017,我想它应该适用于任何使用Windows官方Git的应用程序)。



由于我已经安装了Pageant并创建了一个.ppk私钥,我只需要通过创建 GIT_SSH Windows环境变量并将其设置为plink.exe文件的路径(在PuTTY安装中,例如 C:\程序文件(x86)\PTTTY\plink .EXE )。完成之后,我只需要打开Pageant并添加私钥(并在使用存储库时保持打开状态),Visual Studio就能够连接并发出命令。


I'm trying to connect to a Git repository (on Bitbucket) with SSH from Visual Studio 2017 (which, as far as I know, supports SSH for Git). I have everything set up, the repository cloned on my computer, and I can commit, but if I try to do something like fetching it fails with the following message (from Visual Studio's "Output" window):

Error encountered while fetching: Git failed with a fatal error.
fatal: Could not read from remote repository.

Trying it from the command prompt, I get these slightly more informative messages:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

From Git Bash I have tried opening the SSH agent, adding my private key, and fetching, and it seems to work (or at least I don't get any messages, unlike when the agent is not started or the key not added):

eval `ssh-agent`
ssh-add ~/.ssh/xxxx
git fetch

But Visual Studio is still unable to connect. I have also tried to do the same from the Windows command prompt:

ssh-agent
set SSH_AUTH_SOCK=/tmp/ssh-SIAryCa61iz9/agent.11128
set SSH_AGENT_PID=9804
ssh-add xxxx
git fetch

But I still get the same error.

I already added the public key to Bitbucket, and ssh -T git@bitbucket.org does output "logged in as xxxx". Also, I can connect correctly using SourceTree and adding the private key to Pageant (the key I use for ssh-add has the required OpenSSH format, I created it from the .ppk one).

解决方案

I finally managed to make it work, using PuTTY's Pageant authentication agent instead of ssh-agent, and following the steps mentioned here (it's for Visual Studio Code, but works for Visual Studio 2017 and I guess it should work for any application that uses the "official" Git for Windows).

Since I already had Pageant installed and a .ppk private key created, I only had to make Git use Pageant, by creating the GIT_SSH Windows environment variable and setting it to the path of the "plink.exe" file (inside the PuTTY installation, for example C:\Program Files (x86)\PuTTY\plink.exe). With that done, I just need to open Pageant and add the private key (and leave it open while working with the repository), and Visual Studio will be able to connect and issue commands just fine.

这篇关于使用Visual Studio 2017使用SSH连接到Git存储库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆