【问题标题】:Bitbucket ssh public key is being denied but their ssh test connects with no issueBitbucket ssh 公钥被拒绝,但他们的 ssh 测试连接没有问题
【发布时间】:2015-07-27 18:10:20
【问题描述】:

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

似乎可以正常登录。那么...为什么 push 不起作用?上面的链接提到这可能是项目本身的权限问题,但我按照人们的建议设置了权限,但它什么也没做。有人知道怎么回事吗?

【问题讨论】:

    标签: git ssh bitbucket ssh-keys


    【解决方案1】:
    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
    

    【讨论】:

    • 谢谢,太尴尬了。
    【解决方案2】:

    如果你这样做了:

    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
    

    【讨论】:

    • 嗯,是git@,他用的是git而不是hg
    • 如果你去阅读问题(w/bitbucket 的输出),你会发现任何一个都应该工作。由于 OP 在问题中使用hg@,因此我坚持这样做。我同意这令人困惑。我会更新答案。
    • 啊,我明白了。感谢您的澄清!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-05-10
    • 1970-01-01
    • 2019-10-22
    • 2021-01-21
    • 1970-01-01
    • 2019-11-23
    • 2020-02-11
    相关资源
    最近更新 更多