git 源树 SSH 公钥被拒绝
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/22021378/
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
Source Tree SSH Public Key Denied
提问by t0mgs
I'm working on a project in a private repository on https://www.bitbucket.com.
我正在https://www.bitbucket.com上的私有存储库中处理一个项目。
I'm coding it locally, then staging, commiting and pushing the update vie BitBucket's Windows Git client, Sourcetree.
我在本地编码,然后暂存、提交和推送更新 vie BitBucket 的 Windows Git 客户端Sourcetree。
After that, I'm pulling the files from a remote sharedserver, which requires SSH authentication.
之后,我从远程共享服务器中提取文件,这需要 SSH 身份验证。
I've tried the following in order to connect the git repo with the bitbucket account:
为了将 git repo 与 bitbucket 帐户连接,我尝试了以下操作:
- Launched the embedded Sourcetree SSH agent (Pageant)
- Added my .ppk (PuTTY Private Key) to Pageant using my passphrase
- Opened the SourceTree Terminal in the location of my project, let's call it
C:/Project
. - Used
git init
to initialize the repository. - Used
git push -u origin --all
in order to push the repo from my computer to BitBucket. - Got this error:
Permission denied (publickey).
- Tried to see if I can
ssh -Tv [email protected]
- Still,Permission denied
.
- 推出嵌入式 Sourcetree SSH 代理 (Pageant)
- 使用我的密码将我的 .ppk(PuTTY 私钥)添加到 Pageant
- 在我的项目所在的位置打开SourceTree Terminal,我们称之为
C:/Project
. - 用于
git init
初始化存储库。 - 用于
git push -u origin --all
将 repo 从我的计算机推送到 BitBucket。 - 得到这个错误:
Permission denied (publickey).
- 试图看看我是否可以
ssh -Tv [email protected]
- 仍然,Permission denied
。
I'm trying to figure out what exactly went wrong - has it found my SSH key at all? Is the key not loaded in a specific place?
我想弄清楚到底出了什么问题 - 它是否找到了我的 SSH 密钥?密钥是否未加载到特定位置?
Note:I have loaded the public key in my profile on BitBucket.
注意:我已在 BitBucket 上的个人资料中加载了公钥。
采纳答案by t0mgs
Well - I've found the solution after much trial and error.
Apparently, using PUTTY's keygen and storing the new public key in my .ssh
folder doesn't work.
However, using ssh-keygen
IN GIT BASHand then trying to login using the new generated key pair, works just fine.
Out of curiosity though more than anything - I would love to know why this is the case.
好吧 - 经过多次反复试验,我找到了解决方案。显然,使用 PUTTY 的密钥生成器并将新的公钥存储在我的.ssh
文件夹中是行不通的。但是,使用ssh-keygen
IN GIT BASH然后尝试使用新生成的密钥对登录,效果很好。出于好奇,但最重要的是 - 我很想知道为什么会这样。
回答by Maher Abuthraa
To whom may have the same issue on Mac with new Sierra. Solution would be to add private key to SSH agent via:
谁可能在 Mac 上使用新的 Sierra 遇到同样的问题。解决方案是通过以下方式将私钥添加到 SSH 代理:
ssh-add -K ~/.ssh/id_rsa
It looks like that identity[id_rsa] doesn't persist by SSH agent.
看起来身份 [id_rsa] 不会被 SSH 代理持久化。
Note this is not a permanent solution .. You would need to do that each time you clone a new repository.At least then no need to provide private key for each push to remote.
请注意,这不是一个永久的解决方案.. 每次克隆新存储库时都需要这样做。至少不需要为每次推送到远程提供私钥。
-------- Update 28.Sep.2017 --------
-------- 2017 年 9 月 28 日更新 --------
Permanent solution ( On Sierra):
永久解决方案(在 Sierra 上):
Steps:
脚步:
1- Be sure that you have a running ssh-agent in background before doing anything.
1- 在做任何事情之前,请确保您在后台有一个正在运行的 ssh-agent。
To check if ssh-agent is running by:
要检查 ssh-agent 是否正在运行,请执行以下操作:
pgrep 'ssh-agent'
That command returns PID (ProcessID) of that process if it's running. If you see a value.. Go to Step#2. if not, so you need to run that agent in background by:
如果该进程正在运行,该命令将返回该进程的 PID (ProcessID)。如果您看到一个值.. 转到步骤#2。如果没有,那么您需要通过以下方式在后台运行该代理:
eval "$(ssh-agent -s)"
2- Edit ~/.ssh/config
(Create if it doesn't exist as su
):
2- 编辑~/.ssh/config
(如果不存在则创建su
):
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
3- Then add that key agent ( that would be once ):
3-然后添加该关键代理(即一次):
ssh-add -K ~/.ssh/id_rsa
That's it.
就是这样。
Actually Step#2 is the crucial one. I just want to provide a complete guide.
实际上,第 2 步是关键的一步。我只想提供一个完整的指南。
I hope that may help you.'.
我希望这可以帮助你。'。
回答by ApceH Hypocrite
I needed to further modify these settings SourceTree:
我需要进一步修改这些设置 SourceTree:
回答by Frédéric Bolduc
I know this is resolved, but to add to the accepted answer, you don't actually need Git Bash in order for this to work. As Cupcake said, it is true that PuTTY puts out .ppk
files for private keys, which won't work outside the usual PuTTY/Pageant context.
我知道这已解决,但要添加到已接受的答案中,您实际上并不需要 Git Bash 才能使其正常工作。正如 Cupcake 所说,PuTTY 确实.ppk
为私钥提供了文件,这在通常的 PuTTY/Pageant 上下文之外不起作用。
This is because the terminal expects by default to find a file named id_rsa
in ~/.ssh
and PuTTY doesn't generate that by default. Git Bash's ssh-keygen
does though, which is why Tom Granot's solution works.
You CAN, though, through the PuTTY key generator, export the same exact file through the Conversions/Export OpenSSH Key...
option in the menu. Just be sure to name it id_rsa
and have it sit next to your id_rsa.pub
file, and everything should work fine.
这是因为终端默认情况下希望找到名为id_rsa
in的文件,~/.ssh
而 PuTTY 默认不会生成该文件。ssh-keygen
不过,Git Bash可以,这就是 Tom Granot 的解决方案有效的原因。不过,您可以通过 PuTTY 密钥生成器,通过Conversions/Export OpenSSH Key...
菜单中的选项导出完全相同的文件。只要确保命名它id_rsa
并将其放在您的id_rsa.pub
文件旁边,一切都应该正常工作。
回答by Rashad Akoodie
This happened to me after updating my Sourcetree on my Mac.
What worked for me was just simply removing everything in the ~/.ssh/
folder except the .config
and the known_hosts
folders. Then simply go to sourcetree under preferences, remove your github account, re-add the profile again after deleting all the .ssh
public and private keys and sourcetree should re-add the keys locally and to GitHub
在我的 Mac 上更新我的 Sourcetree 后,这发生在我身上。对我有用的只是简单地删除~/.ssh/
文件夹中除.config
和known_hosts
文件夹之外的所有内容。然后只需转到首选项下的 sourcetree,删除您的 github 帐户,在删除所有.ssh
公钥和私钥后再次重新添加配置文件,sourcetree 应在本地和 GitHub 上重新添加密钥
回答by Absolutkarlos
This is an old question, but every time there is a MacOS update, I came across this issue. Catalina was no exception.
这是一个老问题,但每次有 MacOS 更新时,我都会遇到这个问题。卡特琳娜也不例外。
First, you should check your config file to confirm if your old keys still there... it should:
首先,您应该检查您的配置文件以确认您的旧密钥是否仍然存在......它应该:
~ ls -al ~/.ssh
Then you have to add again your key(s) by the name listed above:
然后,您必须按上面列出的名称再次添加您的密钥:
~ ssh-add -K ~/.ssh/[key-name]