我有2个bitbucket帐户 - 一个用于工作,一个用于个人。
默认情况下,我正在使用工作帐户,但现在需要从个人帐户下的存储库中克隆一些代码并出现此错误:
git clone git@bitbucket.org:my_personal/project.git
Cloning into 'project'...
repository access denied.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我在笔记本电脑上为个人Bitbucket帐户生成了一组新密钥 - personal
和personal.pub
。我将此personal
密钥添加到个人BB帐户的SSH帐户设置中。
然后,我设置了/Users/adam/.ssh/config
文件:
# Work account
Host bitbucket.org
HostName bitbucket.org
User my_working_bb_id
PreferredAuthentications publickey
IdentityFile ~/.ssh/id_rsa
# Personal account
Host bitbucket.org_personal
HostName bitbucket.org
User personal_bb_id
PreferredAuthentications publickey
IdentityFile ~/.ssh/personal
我也跑了ssh-add -l
:
2048 SHA256:bYwG+K01In4aDtux36u58ywVqhmALTandY4h8yEg7YE /Users/adam/.ssh/id_rsa (RSA) # <- work-account
2048 SHA256:I3FFdzuS1a3oVy2LAgE+Uh3iQfDIYwys24ZMAAwT0B0 /Users/adam/.ssh/id_rsa_test@gmail.com (RSA)
2048 SHA256:ye3efWFfSt5tOqj7+APV9eU/Q7lquvbJc0GywyuGm68 /Users/adam/.ssh/presonal (RSA)
2048 SHA256:aGsdBd6lqTqRBXuusvblyUbM9d7Hc5+oJNdVgUwumIM /Users/adam/.ssh/presonal (RSA)
当我运行ssh -T hg@bitbucket.org
时,我得到:
以my_work_bb_id登录。
我怀疑这里(上图)可能是问题?在我的笔记本电脑上,我仍然只使用我的工作BB ID登录?
问题出在哪里?我整个下午都在为这个问题而战,但是无法继续前进。
我会感激你的每一个建议!
答案 0 :(得分:1)
如果〜/ .ssh / config文件中有两个单独的条目,那么您应该可以使用git clone bitbucket.org_personal:owner/repo.git
作为个人用户进行克隆。您还应该能够使用自己的用户名克隆,推送和拉取,而不是“git”或“hg”(类似git clone my_personal_username@bitbucket.org:owner/repo.git
)。
答案 1 :(得分:0)
如果您有更多密钥,则应在配置文件中使用IdentitiesOnly yes
。它将避免使用默认密钥,它将使用配置文件中提供的密钥作为优先级。
当然你需要克隆方式,如另一个答案中所述:使用ssh配置中的主机名别名:
git clone git@bitbucket.org_personal:my_personal/project.git