生成多个公私密钥对

1
2
ssh-keygen -t rsa -f id_rsa_local
ssh-keygen -t rsa -f id_rsa_company

公钥填入对应账户

https://bitbucket.org/account/settings/ssh-keys/

add key

修改host

C:\Windows\System32\drivers\etc\hosts追加

1
company bitbucket.org

域名和私钥映射

C:\Users\<你的用户名>\.ssh追加

1
2
3
4
5
6
7
8
9
Host bitbucket.org
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile C:\Users\<你的用户名>\.ssh\id_rsa_local

Host company
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile C:\Users\<你的用户名>\.ssh\id_rsa_company

使用

个人的账户还用 git clone git@bitbucket.org:xxx/xxx.git

公司账户就用 git clone git@company:xxx/xxx.git