Bitbucket不同的密钥和帐户

时间:2013-02-18 12:57:56

标签: git github bitbucket account

是否有任何方法可以配置ssh为bitbucket(或github)的每个帐户使用不同的密钥?

我的意思是,如果我要使用*.bitbucket:user1 ssh应该使用密钥id_rsa.user1*.bitbucket:user2应该使用id_rsa.user2

尝试过:

IdentityFile ~/.ssh/id_rsa.user1
IdentityFile ~/.ssh/id_rsa.user2

Host *.bitbucket.org:user1*
  IdentityFile ~/.ssh/id_rsa.user1
  User git

Host *.bitbucket.org:user2*
  IdentityFile ~/.ssh/id_rsa.user2
  User git

但没有运气。

1 个答案:

答案 0 :(得分:3)

使用ssh,您可以使用%HOME%/.ssh/config轻松命名ssh遥控器以使用一组键或另一组键。
(这适用于BitBucket或GitHub)

请参阅示例“change github account mac command line

#User 1 on BitBucket
Host bitbucketu1
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/id_rsa.user1

#User 2 on BitBucket
Host bitbucketu2
  HostName bitbucket.org
  User git
  IdentityFile ~/.ssh/id_rsa.user2

然后,git clone bitbucketu1:repo1将从user1克隆一个repo。