由于项目开发需要,可能多个项目都放在bitbucket或者github上面,每个项目都有独立的sshkey,这就会造成push时的系统默认取~/.ssh/id_rsa的问题。
最简单的解决方法是这样:
vi ~/.ssh/config
Host bitbucket-project1 #设置git用的假hostname
HostName bitbucket.org #这里是真实的hostname
User git
IdentityFile ~/.ssh/id_rsa.pro1 #指向项目的私钥
IdentitiesOnly yes
Host bitbucket-project2
HostName bitbucket.org
User git
IdentityFile ~/.ssh/id_rsa.pro2
IdentitiesOnly yes
测试效果:
ssh -T git@bitbucket-project1 #用config里设置好的假域名替换真实域名
logged in as project1.
ssh -T git@bitbucket-project2
logged in as project2.
对应项目下的.git/config修改:
project1:
url = git@bitbucket-project1:accountname1/projectname1.git
project2:
url = git@bitbucket-project2:accountname2/projectname2.git