我创建了一对新的专门用于使用bitbucket的ssh密钥,它们位于我的~/.ssh
文件夹中,如下所示:
config
id_rsa.pub
id_rsa_alt.pub
id_rsa
id_rsa_alt
我想将rsa_alt密钥对用于bitbucket。
首先,我将id_rsa_alt.pub
的内容添加到了我的Bitbucket帐户中。
我意识到,当我尝试通过SSH连接到我的bitbucket帐户时,将不知道是否使用替代密钥对的原始密钥对。因此,我在config
内的~/ .ssh
文件中添加了以下内容。
# 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':
我在做什么错了?
答案 0 :(得分:0)
如果要使用在~/.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