我已经安装了Git for Windows(配置为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.
当我运行建议的ssh -v hg@bitbucket.org
时,它使用了id_rsa
但~/.ssh
中没有其他任何键。尝试使用ssh-add ~/.ssh/bitbucket_rsa
会导致:
Could not open a connection to your authentication agent.
我已经阅读过关于配置PuTTY以允许转发的内容,但这通常是建议结束的地方,因此我只为默认会话设置此选项并将其保存在那里。
我运行ps
来检查哪些应用程序正在运行,ssh-agent
不在其中。正在运行eval 'ssh-agent'
启动守护程序,但它没有任何区别。
答案 0 :(得分:73)
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.
Environment
into your Windows 10 search bar. Otherwise, open up System Properties / Advanced System Settings and find your Environment Variables.plink.exe
file (you may also have pageant.exe
and puttygen.exe
in the same folder).
C:\Program Files (x86)\Atlassian\SourceTree\tools\putty\plink.exe
plink.exe
and put it somewhere that's not going to change.plink.exe
.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.
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.
git@bitbucket.org:USERNAME/REPO_NAME.git
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.
You may need to add your key to the keychain especially if you're using VSCode and have a passphrase on your key (Currently VSCode will not allow you to type in a passphrase).
ssh-add -K ~/.ssh/id_rsa
I'm not sure if these may be helpful for someone, but I've been following getting SSH support into VSCode for Windows: https://github.com/Microsoft/vscode/issues/13680.
答案 1 :(得分:4)
你正在混淆。
PuTTY和Pageant与openSSH工具不兼容,无法一起通信。 PuTTY无法从openssh代理读取密钥,而openssh无法从Pageant读取密钥。关键格式也不同。在这个世界上这是件坏事,但目前还没有解决方案。
还有"代理转发"与使用代理商#34;
不同如果您使用plink设置Git(请确保您确实这样做了),请检查您的Pageant是否正在运行,以及如果您在PuTTY中的存储配置文件中连接 - > SSH-> Auth,选项"尝试使用Pageant"进行身份验证检查。
如果它无法解决您的问题,请从putty发布一些调试日志。
答案 2 :(得分:2)
你不需要putty在ssh中使用BitBucket:在git-for-windows中打包的openssh(C:\prgs\git\PortableGit-2.7.0-64-bit\usr\bin\ssh.exe
)工作正常。
确保在当前的shell会话中,将HOME设置为%USERPROFILE%
(PortableGit-2.7.0-64-bit\git-cmd.exe
足以打开正常配置的常规CMD)
在%USERPROFILE%\.ssh
中创建一个名为config
的文件(如step 3 of the Atlassian doc所示):
Host bitbucket.org
IdentityFile ~/.ssh/bitbucket_rsa
(您也可以使用" /C/path/to/bitbucket_rsa
")
允许使用类似bitbucket.org:user/repo
的ssh网址
使用ssh -Tv bitbucket.org
进行测试(当然,在将您的公钥添加到BitBucket帐户之后)
注意:仅当您的私钥受密码保护时才需要ssh-agent
。
更新2018年,2年后:" Say Farewell to Putty as Microsoft adds an OpenSSH Client to Windows 10"。
现在是时候抛弃腻子:不需要不同的(ppk)密钥格式和proprietary solution,现在openssh正式分发为Windows功能(目前处于测试阶段,2018年第一季度)。
答案 3 :(得分:1)
要从git bash(Git-on-Windows附带)访问Pegeant中加载的ssh密钥,您可以使用this program。安装过程在链接页面上进行了描述。
答案 4 :(得分:1)
在Windows 7中使用git bash对我有用的方法:将.pkk文件转换为open-ssh格式:
将生成的密钥添加到git bash上的IdentityFile .ssh / config中,例如:
Host repo
# my converted open-ssh key
IdentityFile /c/Users/me/open-ssh.pri
# this repo-server uses specific name, not usually needed
User git
# this repo-server uses specific port, not usually needed
Port 8322
# repo server full name
Hostname repo.server.com
答案 5 :(得分:0)
对于未来的Google员工,
只要喜欢@CTS_AE所说的,或者您可以在提升的Powershell中运行它
[Environment]::SetEnvironmentVariable("GIT_SSH", "C:\Program Files\PuTTY\plink.exe", "Machine")