How to use different keys for different Bitbucket

2019-06-06 00:21发布

When using SmartGit as SSH-client, it caches the first selected key. And when further you trying to pull/push to another repo, SmartGit says "Access denied".

SmartGit saves to preferences what key should it use to connect to the Bitbucket. But all repos has address: ssh://git@bitbucket.org in SmartGit preferences.

1条回答
干净又极端
2楼-- · 2019-06-06 01:18

As mentioned here and in this thread, you should be able to reference multiple private ssh keys in a %HOME%\.ssh\config file, changing the url to bitbucket1:userA/myrepo1, bitbucket2:userA/myrepo2.

That means that:

  • you have selected System SSH in the preferences
  • have added a %HOME%\.ssh\config file with:

config:

host bitbucket1
        user git
        hostname bitbucket.org
        port 22
        identityfile /C/path/to/.ssh/key1
host bitbucket2
        user git
        hostname bitbucket.org
        port 22
        identityfile /C/path/to/.ssh/key2
  • in /C/path/to/.ssh/, you have a key1 (private) and key1.pub (public) ssh files (same for key2/key2.pub)
查看更多
登录 后发表回答