Bitbucket ssh公钥被拒绝,但他们的ssh测试连接没有问题

时间:2015-07-27 18:10:20

标签: git ssh bitbucket ssh-keys

一条很可能相关的信息是我为bitbucket设置了自定义ssh配置。在我的'.ssh / config'文件中,我有以下内容:

[ivanna@comp]$ cat ~/.ssh/config 
Host bitbucket
    Hostname        bitbucket.org
    IdentityFile    /home/ivanna/.ssh/id_rsa_bitbucket
    IdentitiesOnly yes

就ssh而言,此文件的权限肯定是正确的(我主动使用配置文件中的其他条目)。现在,当我在git中添加远程源时,我使用了bitbucket而不是bitbucket.org:

git remote add origin bitbucket:ivanna/my-repo.git

但是当我尝试推送时,我收到以下错误:

Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

所以好像我没有添加我的公钥或其他什么,对吧?但我绝对做到了。当您搜索更多信息时,您会找到有关错误的页面(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.

似乎可以正常登录。那么......为什么不推动工作呢?上面的链接提到它可能是项目本身的权限问题,但我按照人们的建议设置了权限,但没有做任何事情。有谁知道发生了什么事?

2 个答案:

答案 0 :(得分:7)

ssh -T hg@bitbucket

通过SSH登录时使用hg@bitbucket,但是在添加到Git的远程URL中,您没有指定用户名。由于配置也不包含一个,Git将不知道登录的用户名。

将网址更改为:

git remote add origin git@bitbucket:ivanna/my-repo.git

或者,您可以将用户添加到SSH配置:

Host bitbucket
    Hostname        bitbucket.org
    User            git
    IdentityFile    /home/ivanna/.ssh/id_rsa_bitbucket
    IdentitiesOnly yes

答案 1 :(得分:4)

如果你这样做了:

git remote add origin bitbucket:ivanna/my-repo.git

您还没有告诉git它需要以您的用户名以外的方式连接。您可以在.ssh/config文件中执行此操作:

Host bitbucket
    User git
    Hostname        bitbucket.org
    IdentityFile    /home/ivanna/.ssh/id_rsa_bitbucket
    IdentitiesOnly yes

或者在你的git remote add命令行中:

git remote add origin git@bitbucket:ivanna/my-repo.git
相关问题