问题1:一台电脑绑定两个git账号,描述:
公司git账号:company 项目名称:CompanyApp
个人git账号:self 项目名称:SelfApp
公司项目在push时正常,但是在个人项目push到远程时提示错误:
zww:SelfApp mac$ git push -u origin master
ERROR: Permission to self/SelfApp.git denied to company.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
或者个人项目push正常时,公司项目push出现
zww:CompanyApp mac$ git push -u origin master
ERROR: Permission to company/CompanyApp.git denied to self.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
因为github是使用SSH key的fingerprint来判定你是哪个账户,而不是通过用户名。这种情况下github无法判断使用哪个.ssh/id_rsa.pub所对应的账户进行登陆。
解决方法:
第一步:配置SSH-Key:
1.生成对应公司和个人git账号的rsa,rsa.pub文件
ssh-keygen -t rsa -C "xxxxx@xxxxx.com"
#这里为了方便区分改变id_rsa文件名字:
Enter file in which to save the key (/Users/mac/.ssh/id_rsa): /Users/mac/.ssh/company_id_rsa
#两次回车即密码设置为空
Enter passphrase (empty for no passphrase):
Enter same passphrase again: