git Bitbucket ssh 公钥被拒绝,但他们的 ssh 测试连接没有问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/31660263/
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
Bitbucket ssh public key is being denied but their ssh test connects with no issue
提问by Ivanna
A quite probably relevant piece of information is that I have a custom ssh config set up for bitbucket. In my '.ssh/config' file I have the following:
一个很可能相关的信息是我为 bitbucket 设置了一个自定义的 ssh 配置。在我的“.ssh/config”文件中,我有以下内容:
[ivanna@comp]$ cat ~/.ssh/config
Host bitbucket
Hostname bitbucket.org
IdentityFile /home/ivanna/.ssh/id_rsa_bitbucket
IdentitiesOnly yes
The permissions on this file are definitely correct as far as ssh is concerned (I actively use other entries in the config file). Now when I added the remote origin in git I used bitbucket instead of bitbucket.org:
就 ssh 而言,此文件的权限绝对正确(我积极使用配置文件中的其他条目)。现在,当我在 git 中添加远程源时,我使用了 bitbucket 而不是 bitbucket.org:
git remote add origin bitbucket:ivanna/my-repo.git
but when I try to push I get the following error:
但是当我尝试推送时,出现以下错误:
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
So it seems like I didn't add my public key or something, right? But I definitely did. And when you search for more information you find this page about the error (https://confluence.atlassian.com/pages/viewpage.action?pageId=302811860). And when I do what they say to do to check the key:
所以看起来我没有添加我的公钥之类的,对吧?但我确实做到了。当您搜索更多信息时,您会找到有关错误的此页面(https://confluence.atlassian.com/pages/viewpage.action?pageId=302811860)。当我按照他们说的去做检查密钥时:
[ivanna@comp]$ ssh -T hg@bitbucket
logged in as ivanna.
You can use git or hg to connect to Bitbucket. Shell access is disabled.
It can login fine, it seems. So... why doesn't pushing work? The above link mentions that it could be a permissions issue on the project itself but I set the permissions as people suggested and it did nothing. Anybody know what's going on?
它可以正常登录,似乎。那么......为什么不推动工作?上面的链接提到它可能是项目本身的权限问题,但我按照人们的建议设置了权限,但它什么也没做。有人知道这是怎么回事吗?
采纳答案by poke
ssh -T hg@bitbucket
You use hg@bitbucket
when logging in via SSH, but in the remote URL you add to Git, you don't specify a username. Since the configuration also does not include one, Git won't know what username to log in with.
您hg@bitbucket
在通过 SSH 登录时使用,但在您添加到 Git 的远程 URL 中,您没有指定用户名。由于配置也不包含一个,Git 不知道用什么用户名登录。
Change the URL to this:
将 URL 更改为:
git remote add origin git@bitbucket:ivanna/my-repo.git
Alternatively, you can add the user to the SSH config:
或者,您可以将用户添加到 SSH 配置:
Host bitbucket
Hostname bitbucket.org
User git
IdentityFile /home/ivanna/.ssh/id_rsa_bitbucket
IdentitiesOnly yes
回答by larsks
If you did this:
如果你这样做:
git remote add origin bitbucket:ivanna/my-repo.git
You haven't told git
that it needs to connect as the something other than your username. You could do this in your .ssh/config
file like this:
您还没有告诉git
它需要以您的用户名以外的其他身份进行连接。你可以在你的.ssh/config
文件中这样做:
Host bitbucket
User git
Hostname bitbucket.org
IdentityFile /home/ivanna/.ssh/id_rsa_bitbucket
IdentitiesOnly yes
Or in your git remote add
command line like this:
或者在你的git remote add
命令行中像这样:
git remote add origin git@bitbucket:ivanna/my-repo.git