Git Bash和Pageant没有使用密钥 [英] Git Bash and Pageant are not using keys
问题描述
我已经安装了适用于Windows的Git(已针对MinTTY和PuTTY\plink.exe
配置)和PuTTY,并且我正在尝试使其与Bitbucket存储库一起使用.我已经在Pageant和网站上加载了SSH密钥,但是无论何时尝试执行任何需要拉动/推动的操作:
I've got Git for Windows (configured for MinTTY and PuTTY\plink.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.
推荐答案
这最终对我有用.
顺便说一句,我在Windows上也有Bash,但我认为这并不重要.
BTW, I do have Bash on Windows as well, but I don't think that matters.
我安装了Sourcetree,并用plink.exe
,puttygen.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.
- 在Windows 10搜索栏中键入
Environment
.否则,请打开系统属性"/高级系统设置",然后找到您的环境变量. - 添加新的系统变量
- 变量名称:GIT_SSH
- 变量值:
plink.exe
文件的完整路径(您可能在同一文件夹中也有pageant.exe
和puttygen.exe
).-
我的是:
C:\Program Files (x86)\Atlassian\SourceTree\tools\putty\plink.exe
-
- Type
Environment
into your Windows 10 search bar. Otherwise, open up System Properties / Advanced System Settings and find your Environment Variables. - Add a new System variable
- Variable Name: GIT_SSH
- Variable Value: full path to
plink.exe
file (you may also havepageant.exe
andputtygen.exe
in the same folder).Mine was:
C:\Program Files (x86)\Atlassian\SourceTree\tools\putty\plink.exe
注意:较新版本的Sourcetree似乎安装了%localappdata%
.工具位于%localappdata%\SourceTree\app-x.x.x\tools\putty
Note: Newer versions of Sourcetree seem to install ot %localappdata%
. The tools are located at %localappdata%\SourceTree\app-x.x.x\tools\putty
注意:较新的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代码中为集成终端运行Bash,所以我不得不重新启动Visual Studio代码.关闭集成终端并打开新终端肯定是可以接受的,但是我也希望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
- ssh layout:
git@bitbucket.org:USERNAME/REPO_NAME.git
- https layout:
https://USERNAME@bitbucket.org/USERNAME/REPO_NAME.git
我注意到在Windows 10上使用HTTPS时,它将使用Windows凭据管理器(我试图向自己添加凭据时试图自己解决这个问题,但是我仍在使用SSH,所以没关系)与远程存储库进行交互,它将提示您输入凭据,并将其存储以供以后在Windows Credential Manager中使用:)
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
我不确定这些方法是否对某人有用,但是我一直在为Windows的Visual Studio Code获得SSH支持:
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.
- https://github.com/PowerShell/openssh-portable
- https://github.com/rupor-github/ssh-agent-wsl
这篇关于Git Bash和Pageant没有使用密钥的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!