一台电脑多个git使用 push 时候出现denied

http://my.oschina.net/silentboy/blog/220158

当一台电脑上多个git account 的时候, 出现如下问题,

 

$ git push origin master
ERROR: Permission to UserA/touchme.git denied to UserB.
fatal: Could not read from remote repository.

Please make sure you have the correct access rights

 

解决方式

 

http://www.jianshu.com/p/886aea2fa206

1: 取消git config --global 的 user, email 配置, 进入单独项目 单独配置

2: 删除默认的密钥, 重建新的密钥给冲突的account

3:  添加新密钥到config 文件

 

Host github_personal
HostName github.com
User UserA
IdentityFile ~/.ssh/id_personal_rsa
IdentitiesOnly yes

Host github_company
HostName github.com
User UserB
IdentityFile ~/.ssh/id_company_rsa
IdentitiesOnly yes

 

 

如果之后仍然出现验证问题如下:

$ git push origin master
Warning: Permanently added the RSA host key for IP address '192.30.252.122' to the list of known hosts.
Permission denied (publickey).
fatal: Could not read from remote repository.

解决办法: 重置repo 的url 为alias下的url

http://stackoverflow.com/questions/26953071/github-authentication-failed-github-does-not-provide-shell-access

 

参考如下: 

git remote set-url origin git@${alias in config}:UserA/touchme.git

这样就可以正常push 了 

$ git push origin master
Counting objects: 2, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (2/2), done.
Writing objects: 100% (2/2), 363 bytes | 0 bytes/s, done.
Total 2 (delta 1), reused 0 (delta 0)

 

 

验证添加的密钥能否成功连接github:

$ ssh -vT git@${alias}

posted @ 2016-04-07 13:48  IamThat  阅读(537)  评论(0编辑  收藏  举报