Git Bash&选美不使用键 [英] Git Bash & Pageant not using keys

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

问题描述

我的Git for Windows(配置为MinTTY和 PuTTY \plink.exe )并安装了PuTTY,并试图让它与BitBucket一起工作库。我已经加载了我的SSH密钥,在Pageant和网站上,然而每当我尝试做任何需要拉/推的东西时:

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

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

当我运行建议的 ssh -v hg@bitbucket.org 它使用 id_rsa ,但是我的其他密钥在〜/ .ssh 中都没有。尝试使用 ssh-add〜/ .ssh / bitbucket_rsa 导致:

 无法打开与身份验证代理的连接。 

我已经阅读了关于配置PuTTY以允许转发的信息,但通常是通知的结束位置,所以我



我运行了 ps 来检查哪些应用程序正在运行, ssh-agent 不在其中。运行 eval'ssh-agent'启动守护程序,但它没有区别。

解决方案

我的确在Windows上有bash,但我认为这不重要。

p>

我安装了SourceTree并使用 plink.exe puttygen.exe ,& pageant.exe 。您也可以单独下载并安装它们。



配置Windows环境变量




  1. 在Windows 10搜索栏中输入 Environment 。否则,请打开系统属性/高级系统设置并找到您的环境变量。

  2. 添加新的系统变量


    • 变量名称:GIT_SSH

    • 变量值:指向 plink.exe 文件(也可能在同一个文件夹中有 pageant.exe puttygen.exe )。


      • Mine是: C:\程序文件(x86)\Atlassian\SourceTree\tools\putty\注意:较新的SourceTree(Windows版v2)使用版本化的目录,因此每次更新它时,都会必须更新这是一个痛苦。最好只是制作 plink.exe 的副本,并放在不会改变的地方。

      • 如果您有任何上述程序运行时,您可以随时打开任务管理器,查找进程并打开文件夹位置以获取 plink.exe 的路径。





利润



确保重新启动终端,以便它们获得更新的环境变量。对我而言,我在VSCode中为我的集成终端运行bash,所以我必须重新启动VSCode。关闭集成终端并打开一个新终端肯定会被接受,但我也希望VSCode中的内置git功能也能正常工作。



注意



考虑到我安装了SourceTree,我可以使用它的接口从BitBucket中克隆并通过它的接口,但通过终端尝试不工作,因为他们正在使用一个不同的证书集。

另一个有趣的事情是,如果您导航到您的项目的git配置位于: ./。git / config ,你可以使用ssh替换你的远程到https。您可以从您的BitBucket存储库中的概览中获取以下值。




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

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


我注意到在Windows 10上使用https时,它将使用Windows Credential Manager(我尝试添加我的凭据在尝试自己弄清楚的时候,但我仍在使用SSH,因此它并不重要)当您与远程存储库进行交互时,它会提示您输入凭据并将其存储以供以后在Windows Credential Manager中使用: )



希望这些方法中的一种可以为您解决。 HTTPS方法将跳过整个SSH密钥生成并将其推送到BitBucket中,但对我来说感觉更安全和便携。


I've got Git for Windows (configured for MinTTY and PuTTY\plink.exe) and PuTTY installed, and 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.

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.

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.

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.

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

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.

Configure Windows Environment Variable

  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)\Atlassian\SourceTree\tools\putty\plink.exe
      • Note: The newer SourceTree (v2 on Windows) uses versioned directories so everytime 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.
      • 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.

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 VSCode, so I had to restart VSCode. 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 VSCode to work as well.

Note

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.

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.

  • shh layout: git@bitbucket.org:USERNAME/REPO_NAME.git
  • https layout: https://USERNAME@bitbucket.org/USERNAME/REPO_NAME.git

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 :)

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 feels more secure and portable for me.

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

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