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

Bitbucket ssh public key is being denied but their ssh test connects with no issue

一条很可能相关的信息是我为 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.

看来我没有添加 public 密钥之类的,对吧?但我确实做到了。当您搜索更多信息时,您会找到有关该错误的页面 (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.

好像可以正常登录。那么......为什么不推动工作?上面 link 提到它可能是项目本身的权限问题,但我按照人们的建议设置了权限,但它什么也没做。有人知道怎么回事吗?

如果你这样做了:

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
ssh -T hg@bitbucket

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

将 URL 更改为:

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