简体   繁体   English

在Windows下使用带有SSH密钥文件的GIT时出现问题

[英]Problems using GIT w/ SSH key file under Windows

I've problems using GIT with the shell, Visual Studio Code and Visual Studio 2015 (community edition). 我在将GIT与外壳,Visual Studio Code和Visual Studio 2015(社区版)一起使用时遇到问题。

Earlier this year I started using GIT with eGit (under Eclipse of course) without any problems. 今年早些时候,我开始将GIT与eGit一起使用(当然是在Eclipse下),没有任何问题。 I installed GIT on my server, created a ssh key pair and after a few tests it worked (and still works). 我在服务器上安装了GIT,创建了一个ssh密钥对,并在进行了几次测试后仍然有效(并且仍然有效)。

However, now I want to use that GIT on my server with Visual Studio Code and maybe later with Visual Studio 2015. 但是,现在我想在服务器上将GIT与Visual Studio Code一起使用,也许以后再与Visual Studio 2015一起使用。

I got stuck on this issue: GIT trys to use my PPK and asks me for the passphrase (which is emtpy). 我遇到了这个问题:GIT尝试使用我的PPK并要求我输入密码(这是空的)。 If I enter a wrong phrase it asks again and continues only if I answer correct (simply enter key). 如果我输入了错误的短语,它会再次询问,并且仅在我回答正确(仅输入键)时才继续。 So I think everything is OK till here. 所以我认为到这里一切都还可以。 But then it asks for the user password for the git-user (the right one btw) on the server and fails. 但是随后,它要求服务器上的git-user(右边的一个顺便说一句)的用户密码,但失败了。 Why? 为什么?

In the log of my server I can't see any entry about logging in using the key file, only the errors about trying to log in with the password (which is disabled). 在服务器的日志中,我看不到任何有关使用密钥文件登录的条目,仅看到有关尝试使用密码(已禁用)登录的错误。

If I use putty with that key file I'm able to connect to my GIT server and I also get an entry in the log file. 如果我将腻子与该密钥文件一起使用,则可以连接到我的GIT服务器,并且还会在日志文件中获得一个条目。 So I'm sure that everything is OK with the server. 因此,我确定服务器一切正常。

What am I missing? 我想念什么? I would appreciate any help about that! 我将不胜感激!

Using it with Visual Studio 2015 (I can't solve the issue that it doesn't find libssh when I try to recompile the GIT module following the well known blog entry from Bernardo Pastorelli) or saving the enter key press would be a bonus, however, I would be happy if I could use GIT with key file under Shell / Visual Studio Code at all. 在Visual Studio 2015中使用它(当我在Bernardo Pastorelli的著名博客条目之后尝试重新编译GIT模块时,无法解决libssh找不到libssh的问题)或保存回车键将是一个奖励,但是,如果可以在Shell / Visual Studio Code下的密钥文件中使用GIT,我将非常高兴。

OS: Windows 7 64 bit 操作系统:Windows 7 64 bit
GIT 2.10.2.windows.1 GIT 2.10.2.windows.1
VSC: V 1.7.2 VSC:V 1.7.2

TIA! TIA!

I'll try to answer the simpler question in your Post: 我将尝试在您的帖子中回答更简单的问题:

I would be happy if I could use GIT with key file under Shell 如果可以在Shell下将GIT与密钥文件一起使用,我会很高兴

Once, that is done, you can build on it. 一旦完成,就可以在此基础上进行构建。


Git for windows uses Openssh and therefore will not be able to use the putty PPK file directly. Windows的Git使用Openssh,因此将无法直接使用腻子PPK文件。

Two ways forward 两种前进方式

Option 1: Convert PPK file to OpenSSH format 选项1:将PPK文件转换为OpenSSH格式

Steps to do so: 步骤如下:

  1. Open your private key in PuTTYGen 在PuTTYGen中打开您的私钥
  2. Top menu “Conversions”->”Export OpenSSH key”. 顶部菜单“转换”->“导出OpenSSH密钥”。
  3. Save the new OpenSSH key when prompted. 出现提示时,保存新的OpenSSH密钥。

To use this new openssh key for your git server, do the following: 要将这个新的openssh密钥用于git服务器,请执行以下操作:

Open up Git Bash shell and there edit ~/.ssh/config (create ~/.ssh/ if it does not exist) and define this host: 打开Git Bash shell,然后编辑~/.ssh/config (如果不存在,则创建~/.ssh/ )并定义以下主机:

Host AuxBurgerGitServer
   Hostname whatevers-your-git-remote-is
   User     the-git-user
   IdentityFile ~/.ssh/the-open-ssh-key-exported-before

Test this by doing a ssh -T AuxBurgerGitServer which should not show any errors. 通过执行ssh -T AuxBurgerGitServer进行测试,该ssh -T AuxBurgerGitServer不应显示任何错误。

If you go this way, you should use the HOST defined above whenever referring to any repositories on this host. 如果采用这种方式,则在引用此主机上的任何存储库时都应使用上面定义的HOST Therefore, for example, to clone a repo you would do something like: 因此,例如,要克隆存储库,您可以执行以下操作:

git clone ssh://AuxBurgerGitServer/some-repo-name

Option 2: Configure your GIT to use pageant 选项2:将您的GIT配置为使用选美

You can load your PPK file in pageant and configure GIT to use pageant for authentication. 您可以将PPK文件加载到页面中,并将GIT配置为使用页面进行身份验证。

For this, the only thing you would need is to setup an environment variable like so using: 为此,您唯一需要做的就是使用以下方法设置环境变量:
Control Panel → System → Advanced system settings → Environment variables
(or on Windows 10: Control Panel → Search → Environment variables ) (或在Windows 10上: Control Panel → Search → Environment variables

GIT_SSH=c:\Program Files\Putty\plink.exe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM