windows Git Bash 和 Pageant 不使用密钥
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35110079/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git Bash and Pageant are not using keys
提问by Dissident Rage
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:
我已经安装了适用于 Windows 的 Git(为 MinTTY 和 配置PuTTY\plink.exe
)和 PuTTY,我正在尝试让它与 Bitbucket 存储库一起使用。我已经在 Pageant 和网站上加载了我的 SSH 密钥,但是每当我尝试做任何需要拉/推的事情时:
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 [email protected]
it uses id_rsa
but none of my other keys in ~/.ssh
. Trying to use ssh-add ~/.ssh/bitbucket_rsa
results in:
当我运行建议时,ssh -v [email protected]
它使用id_rsa
了~/.ssh
. 尝试使用ssh-add ~/.ssh/bitbucket_rsa
结果:
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.
我已经阅读了关于配置 PuTTY 以允许转发的内容,但这通常是建议结束的地方,所以我只是为默认会话设置了这个选项并将其保存在那里。
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.
我跑去ps
检查哪些应用程序正在运行,ssh-agent
但不在其中。运行会eval 'ssh-agent'
启动守护进程,但没有任何区别。
回答by CTS_AE
This is what ended up working for me.
这就是最终对我来说有效的原因。
BTW, I do have Bash on Windows as well, but I don't think that matters.
顺便说一句,我在 Windows 上也有 Bash,但我认为这并不重要。
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.
我安装了 Sourcetree 并用plink.exe
, puttygen.exe
, &指向它的文件夹pageant.exe
。您也可以单独下载和安装这些。
Configure Windows Environment Variable
配置 Windows 环境变量
- 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
- Note: Newer versions of Sourcetree seem to install ot
%localappdata%
. The tools are located at%localappdata%\SourceTree\app-x.x.x\tools\putty
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.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
.
- Mine was:
Environment
在 Windows 10 搜索栏中键入内容。否则,打开系统属性/高级系统设置并找到您的环境变量。添加一个新的系统变量
- 变量名称:GIT_SSH
变量值:
plink.exe
文件的完整路径(您可能也有pageant.exe
和puttygen.exe
在同一文件夹中)。- 我的是:
C:\Program Files (x86)\Atlassian\SourceTree\tools\putty\plink.exe
- 注意:较新版本的 Sourcetree 似乎安装了 ot
%localappdata%
。工具位于%localappdata%\SourceTree\app-x.x.x\tools\putty
注意:较新的 Sourcetree(Windows 上的 v2)使用版本化目录,因此每次更新它时,您都必须更新它,这很痛苦。最好只是制作一个副本
plink.exe
并将其放在不会改变的地方。如果您正在运行上述任何程序,您可以随时打开任务管理器,找到进程,然后打开文件夹位置以获取
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 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.
确保重新启动终端,以便它们获得更新的环境变量。对我来说,我在Visual Studio Code 中为我的集成终端运行 Bash ,所以我不得不重新启动 Visual Studio Code。关闭集成终端并打开一个新终端肯定是可以接受的,但我也希望 Visual Studio Code 中的内置 git 功能也能正常工作。
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.
鉴于我安装了 Sourcetree,我能够使用它的界面克隆出 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 Overviewon your Bitbucket repository.
另一个需要指出的有趣的事情是,如果您导航到位于以下位置的项目的 git 配置:./.git/config
,您可以将您的遥控器从使用 SSH 换成 HTTPS。您可以从Bitbucket 存储库的概览中获取以下值。
- shh layout:
[email protected]:USERNAME/REPO_NAME.git
- https layout:
https://[email protected]/USERNAME/REPO_NAME.git
- 嘘布局:
[email protected]:USERNAME/REPO_NAME.git
- https布局:
https://[email protected]/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 :)
我注意到在 Windows 10 上使用 HTTPS 时,它将使用 Windows 凭据管理器(我尝试将我的凭据添加到它,同时试图自己解决这个问题,但我仍在使用 SSH,所以没关系)当你去交互时使用远程存储库,它会提示您输入凭据并将其存储以供以后在 Windows 凭据管理器中使用:)
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.
希望其中一种方法对您有用。HTTPS 方法将跳过整个 SSH 密钥生成并将其推送到 Bitbucket,但对我来说感觉更安全和便携。
Mac OS
苹果系统
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).
您可能需要将您的密钥添加到钥匙串中,特别是如果您使用的是 Visual Studio Code 并且您的密钥上有密码(目前 Visual Studio Code 不允许您输入密码)。
ssh-add -K ~/.ssh/id_rsa
Additions
添加
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.
我不确定这些是否对某人有帮助,但我一直在关注将 SSH 支持纳入 Visual Studio Code for Windows:https: //github.com/Microsoft/vscode/issues/13680。
回答by Jakuje
You are mixing things up.
你把事情搞混了。
PuTTY and Pageant are not compatible with OpenSSH tools and can't communicate together. PuTTY can't read keys from your OpenSSH agent and OpenSSH can't read the keys from Pageant. The key format is also different. That is a bad thing in this world, but there is no solution on the horizon.
PuTTY 和 Pageant 与 OpenSSH 工具不兼容,无法一起通信。PuTTY 无法从 OpenSSH 代理读取密钥,OpenSSH 无法从 Pageant 读取密钥。密钥格式也不同。这在这个世界上是件坏事,但在地平线上没有解决方案。
Also "agent forwarding" is something different than "using agent".
“代理转发”也不同于“使用代理”。
If you set up Git with plink (make sure you really did), check if your Pageant is running and if the option "Attempt authentication using Pageant" is checked in your stored profile in PuTTY under Connection→ SSH→ Auth.
如果您使用 plink 设置 Git(确保您真的这样做了),请检查您的 Pageant 是否正在运行,以及是否在连接→ SSH→ Auth下 PuTTY 中存储的配置文件中选中了“尝试使用 Pageant 进行身份验证”选项。
If it will not resolve your problems, post some debug log from PuTTY.
如果它不能解决您的问题,请从 PuTTY 发布一些调试日志。
回答by VonC
You don't need PuTTY to work with Bitbucket in ssh: the OpenSSH version (C:\prgs\git\PortableGit-2.7.0-64-bit\usr\bin\ssh.exe
) packaged in git-for-windows works just fine.
您不需要 PuTTY 在 ssh 中使用 Bitbucket:C:\prgs\git\PortableGit-2.7.0-64-bit\usr\bin\ssh.exe
打包在 git-for-windows 中的 OpenSSH 版本 ( ) 工作得很好。
Make sure that, in your current shell session, you have HOME set to %USERPROFILE%
(a PortableGit-2.7.0-64-bit\git-cmd.exe
is enough to open a regular CMD properly configured).
确保在您当前的 shell 会话中,您已将 HOME 设置为%USERPROFILE%
(aPortableGit-2.7.0-64-bit\git-cmd.exe
足以打开正确配置的常规 CMD)。
Create a file named config
in %USERPROFILE%\.ssh
(as in step 3 of the Atlassian documentation):
创建一个名为config
in的文件%USERPROFILE%\.ssh
(如Atlassian 文档的第 3 步):
Host bitbucket.org
IdentityFile ~/.ssh/bitbucket_rsa
(You can also use "/C/path/to/bitbucket_rsa
".)
(您也可以使用“ /C/path/to/bitbucket_rsa
”。)
That allows to use an SSH URL like bitbucket.org:user/repo
.
Test it with ssh -Tv bitbucket.org
(after adding your public key to your Bitbucket account, of course).
这允许使用像bitbucket.org:user/repo
. 测试它ssh -Tv bitbucket.org
(当然,在将您的公钥添加到您的 Bitbucket 帐户之后)。
Note: ssh-agent
is only needed if your private key is passphrase-protected.
注意:ssh-agent
仅当您的私钥受密码保护时才需要。
Update 2018, two years later: "Say Farewell to PuTTY as Microsoft adds an OpenSSH Client to Windows 10". It is really time to ditch putty aside: no need for a different (ppk) key format and proprietary solution, now that OpenSSHis officially distributed as a Windows feature (in beta for now, Q1 2018).
两年后的 2018 年更新:“告别 PuTTY,因为 Microsoft 向 Windows 10 添加了 OpenSSH 客户端”。现在是抛弃腻子的时候了:现在不需要不同的 (ppk) 密钥格式和专有解决方案,现在OpenSSH作为 Windows 功能正式分发(目前处于测试阶段,2018 年第一季度)。
回答by ivangretsky
To access SSH keys loaded in Pegeant from Git Bash, that comes with Git on Windows, you can use this program. The installation process is described on the linked page.
要从 Windows 上的 Git 附带的 Git Bash 访问 Pegeant 中加载的 SSH 密钥,您可以使用此程序。链接页面上描述了安装过程。
回答by apmattil
What worked for me with Git Bash for Windows 7: convert .pkk file to OpenSSH format:
Windows 7 的 Git Bash 对我有用:将 .pkk 文件转换为 OpenSSH 格式:
Add generated key to IdentityFile .ssh/config
at Git Bash, for example:
IdentityFile .ssh/config
在 Git Bash 中添加生成的密钥,例如:
Host repository
# My converted OpenSSH key
IdentityFile /c/Users/me/open-ssh.pri
# This repository server uses a specific name, not usually needed.
User git
# This repository server uses a specific port, not usually needed
Port 8322
# Repository server full name
Hostname repo.server.com