Git Bash 和 Pageant 不使用密钥 [英] Git Bash and Pageant are not using keys

查看:26
本文介绍了Git Bash 和 Pageant 不使用密钥的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了适用于 Windows 的 Git(为 MinTTY 和 PuTTYplink.exe 配置)并安装了 PuTTY,我正在尝试让它与 Bitbucket 存储库一起使用.我已经在 Pageant 和网站上加载了我的 SSH 密钥,但是每当我尝试做任何需要拉/推的事情时:

I've got Git for Windows (configured for MinTTY and PuTTYplink.exe) and PuTTY installed, and I am trying to get it to work with a Bitbucket repository. I've got my SSH key loaded, in Pageant and on the website, and yet whenever I attempt to do anything that requires pulling/pushing:

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

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

当我运行建议的 ssh -v hg@bitbucket.org 时,它使用 id_rsa 但我在 ~/.ssh.尝试使用 ssh-add ~/.ssh/bitbucket_rsa 结果:

When I run the suggested ssh -v hg@bitbucket.org it uses id_rsa but none of my other keys in ~/.ssh. Trying to use ssh-add ~/.ssh/bitbucket_rsa results in:

Could not open a connection to your authentication agent.

我已经阅读了关于配置 PuTTY 以允许转发的内容,但这通常是建议结束的地方,所以我只是为默认会话设置了这个选项并将其保存在那里.

I've read about configuring PuTTY to allow forwarding, but that's usually where the advice ends, so I just set this option for the default session and saved it there.

我已经运行 ps 来检查哪些应用程序正在运行,ssh-agent 不在其中.运行 eval 'ssh-agent' 会启动守护进程,但没有任何区别.

I've run ps to check which applications were running, and ssh-agent was not among them. Running eval 'ssh-agent' starts the daemon, but it makes no difference.

推荐答案

这就是最终对我有用的方法.

This is what ended up working for me.

顺便说一句,我在 Windows 上也有 Bash,但我认为这并不重要.

BTW, I do have Bash on Windows as well, but I don't think that matters.

我安装了 Sourcetree 并用 plink.exeputtygen.exe 和 & 指向它的文件夹pageant.exe.您也可以单独下载和安装它们.

I had Sourcetree installed and pointed at its folder with plink.exe, puttygen.exe, & pageant.exe. You could also download and install these separately as well.

  1. 在 Windows 10 搜索栏中键入 Environment.否则,打开系统属性/高级系统设置并找到您的环境变量.
  2. 添加一个新的系统变量
    • 变量名:GIT_SSH
    • 变量值:plink.exe 文件的完整路径(您可能还有 pageant.exeputtygen.exe 在同一文件夹中).
      • 我的是:C:Program Files (x86)AtlassianSourceTree oolsputtyplink.exe

  1. Type Environment into your Windows 10 search bar. Otherwise, open up System Properties / Advanced System Settings and find your Environment Variables.
  2. Add a new System variable
    • Variable Name: GIT_SSH
    • Variable Value: full path to plink.exe file (you may also have pageant.exe and puttygen.exe in the same folder).
      • Mine was: C:Program Files (x86)AtlassianSourceTree oolsputtyplink.exe

注意:新版本的 Sourcetree 似乎安装在 %localappdata% 上.工具位于 %localappdata%SourceTreeapp-x.x.x oolsputty

Note: Newer versions of Sourcetree seem to install ot %localappdata%. The tools are located at %localappdata%SourceTreeapp-x.x.x oolsputty

注意:较新的 Sourcetree(Windows 上的 v2)使用版本化目录,因此每次更新它时,您都必须更新它,这很痛苦.最好只复制 plink.exe 并将其放在不会更改的地方.

Note: The newer Sourcetree (v2 on Windows) uses versioned directories, so every time you update it, you'll have to update this which is a pain. It is best to just make a copy of plink.exe and put it somewhere that's not going to change.

如果您正在运行上述任何程序,您可以随时打开任务管理器,找到进程,然后打开文件夹位置以获取 plink.exe 的路径.

If you have any of the above programs running you can always open up task manager, find the process, and open up the folder location to get the path to plink.exe.

利润

确保重新启动您的终端,以便它们获得更新的环境变量.对我来说,我在 Visual Studio Code 中为我的集成终端运行 Bash,所以我不得不重新启动视觉工作室代码.关闭集成终端并打开一个新终端肯定是可以接受的,但我也希望 Visual Studio Code 中的内置 git 功能也能正常工作.

Profit

Make sure to restart your terminals so that they get the updated environment variables. For me, I was running Bash for my integrated terminal within Visual Studio Code, so I had to restart Visual Studio Code. It would have surely been acceptable to close the integrated terminal and open a new one, but I also wanted the built in git functionality in Visual Studio Code to work as well.

鉴于我安装了 Sourcetree,我能够使用它的界面从 Bitbucket 中克隆出来并推送它的界面,但是尝试通过终端不起作用,因为它们使用的是不同的凭据集.

Given that I have Sourcetree installed I was able to use its interface to clone down out of Bitbucket and push through its interface, but trying through terminals was not working, because they were using a different credential set.

要指出的另一个有趣的事情是,如果您导航到位于以下位置的项目的 git 配置:./.git/config,您可以将遥控器从使用 SSH 换成 HTTPS.您可以从 Bitbucket 存储库的概览中获取以下值.

Another interesting thing to point out is that if you navigate into your project's git configuration located at: ./.git/config, you could swap out your remote from using SSH to HTTPS. You can grab the following values from your Overview on your Bitbucket repository.

  • ssh 布局:git@bitbucket.org:USERNAME/REPO_NAME.git
  • https 布局:https://USERNAME@bitbucket.org/USERNAME/REPO_NAME.git

我注意到在 Windows 10 上使用 HTTPS 时,它将使用 Windows 凭据管理器(我尝试将我的凭据添加到它,同时试图自己解决这个问题,但我仍在使用 SSH,所以这并不重要)当你去与远程存储库进行交互,它会提示您输入凭据并将其存储以供以后在 Windows 凭据管理器中使用:)

I noticed while using HTTPS on Windows 10 it then will use the Windows Credential Manager (I tried adding my credentials to it while trying to figure this out myself, but I was still using SSH so it didn't matter) When you go to interact with the remote repository it will prompt you for your credentials and store them for later use in Windows Credential Manager :)

希望其中一种方法对您有用.HTTPS 方法将跳过整个 SSH 密钥生成并将其推送到 Bitbucket,但对我来说感觉更安全和便携.

Hopefully one of these methods will work out for you. The HTTPS method will skip the whole SSH key generation and pushing it up into Bitbucket, but it feels more secure and portable for me.

您可能需要将您的密钥添加到钥匙串中,特别是如果您使用的是 Visual Studio Code 并且您的密钥上有密码(目前 Visual Studio Code 不允许您输入密码).

You may need to add your key to the keychain especially if you're using Visual Studio Code and have a passphrase on your key (currently Visual Studio Code will not allow you to type in a passphrase).

ssh-add -K ~/.ssh/id_rsa

https://help.github.com/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent/#adding-your-ssh-key-to-the-ssh-agent

我不确定这些是否对某人有帮助,但我一直在关注将 SSH 支持纳入 Visual Studio Code for Windows:https://github.com/Microsoft/vscode/issues/13680.

I'm not sure if these may be helpful for someone, but I've been following getting SSH support into Visual Studio Code for Windows: https://github.com/Microsoft/vscode/issues/13680.

这篇关于Git Bash 和 Pageant 不使用密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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