同一台机器上的多个 Bitbucket SSH 帐户

Multiple Bitbucket SSH accounts on same machine

我正在尝试通过 SSH 在同一台机器上使用多个 Bitbucket 帐户。

在我的 .ssh\config 文件中,我有:

Host account1.bitbucket.org
  Hostname bitbucket.org
  PreferredAuthentications publickey
  IdentitiesOnly yes
  IdentityFile ~/.ssh/account1

Host account2.bitbucket.org
  Hostname bitbucket.org
  PreferredAuthentications publickey
  IdentitiesOnly yes
  IdentityFile ~/.ssh/account2

然后我将 git 存储库的遥控器更改为使用别名:

git@account1.bitbucket.org:myUserName/myRepoName.git
git@account2.bitbucket.org:myUserName/myRepoName.git

然后在 Pageant(在系统托盘中)中,我添加了我的两个 PPK 密钥。

不幸的是,如果我将两个密钥都添加到 Pageant,则只有一个帐户有效。

如果我在 Pageant 中一次只有一个密钥,那么它将适用于我添加到 Pageant 的任何一个 Bitbucket 帐户。

所以如果列表中有多个键,选美似乎没有使用正确的键。

关于它为什么这样做的任何想法?

我通过不使用 Pageant 来完成这项工作。我将 Sourcetree 用作 Git GUI,在选项中,有一个下拉菜单说明是使用 OpenSSH 还是 Putty/Plink.

根据此处 Steve Streeting 的描述:

https://answers.atlassian.com/questions/164479/sourcetree-support-multiple-ssh-keys

听起来 Pageant 似乎不使用 .ssh\config 配置。

通过更改为 OpenSSH,然后使用 ssh-keygen 重新生成密钥,并通过 Sourcetree 的 "Tools .. Add SSH Keys" 菜单添加私钥,现在可以在多个帐户中使用不同的密钥完美地工作。我只需要更改每个 git 存储库的远程 url 以在配置文件中使用正确的别名(如我最初的 post 中所述)。

更新:

我在这里写了一篇关于此的博客 post: http://www.danclarke.com/multiple-ssh-keys-for-git/

Atlassian Answers 上的这个 link 解释了如何通过多个 bitbucket 帐户使用 PuTTY 和 SSH:

One way to resolve this is to perform the same configuration in PuTTY too to disambiguate what key to send (and therefore which user to authenticate as).

Start PuTTY (download it from putty.org if you don't have it)

Type 'bitbucket.org' in the host name field

Go to Connection > SSH > Auth in the tree

Specify the key to use for the BB user

Go back to 'Session' in the tree

Type an alias name underneath 'Saved Sessions' (e.g. bb-user1) and Save

Repeat 2-6 for each BB user and save as a different session name

Then in your remote URLs, replace 'bitbucket.org' with the session name (e.g. bb-user1) to disambiguate what SSH key to send first. This is identical to using IdentityFile in OpenSSH.

最后,您可以在 pageant 中添加密钥以缓存密钥密码。