【问题标题】:Trying to clone via SSH uses the wrong public key尝试通过 SSH 克隆使用了错误的公钥
【发布时间】:2019-12-21 13:48:13
【问题描述】:

我专门为使用 bitbucket 创建了一对新的 ssh 密钥,它们位于我的 ~/.ssh 文件夹中,如下所示:

configid_rsa.pubid_rsa_alt.pubid_rsaid_rsa_alt

我想为 bitbucket 使用 rsa_alt 密钥对。

首先,我将id_rsa_alt.pub 的内容添加到我的bitbucket 帐户中。

我意识到,当我尝试通过 SSH 连接到我的 bitbucket 帐户时,它不知道是否使用我原来的备用密钥对。所以我在~/ .ssh 内的config 文件中添加了以下内容。

# bitbucket account
Host bitbucket.org-BitBucketUsername
    HostName bitbucket.org
    User git
    IdentityFile ~/.ssh/id_rsa_alt
    IdentitiesOnly yes

我还在我的 mac 上更改了我的 git 名称,如下所示:

git config --global user.name "BitBucketUsername"

但是,当我尝试像这样克隆我的仓库时:git clone git@bitbucket.org:myteam/myproject.git

它要求输入id_rsa 而不是id_rsa_alt 的密码,如下所示:

Enter passphrase for key '/Users/me/.ssh/id_rsa':

我做错了什么?

【问题讨论】:

标签: git macos ssh bitbucket


【解决方案1】:

如果你想使用你在~/.ssh/config中配置的,你需要使用SSH URL:

bitbucket.org-BitBucketUsername:myteam/myproject.git

这将使用~/.ssh/id_rsa_alt 私钥。

所以:

cd /path/to/local/cloned/repository
git remote set-url origin bitbucket.org-BitBucketUsername:myteam/myproject.git

【讨论】:

    猜你喜欢
    • 2015-07-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-10-17
    • 2015-11-15
    • 2016-05-07
    • 2011-11-22
    • 1970-01-01
    相关资源
    最近更新 更多