背景:同一台电脑的public key同时添加到了github的两个账户,导致user1的仓库没法正常提交。
解决办法:为两个账户分别配置ssh key,配置~/.ssh/config文件(windows下也是这个路径,在git bash中可以识别~)
错误:
$ git push
remote: Permission to user1/python.git denied to user2.
fatal: unable to access 'https://github.com/user1/python.git/': The requested URL returned error: 403

解决:

环境:windows 7+ git bash
1、在github上删除两个账户的ssh key
2、生成两个ssh key
切换到ssh key的目录
$ cd ~/.ssh/
只需要修改文件名为user1_rsa, passphrase留空回车即可。
$ ssh-keygen -t rsa -C "user1"
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/waston/.ssh/id_rsa): user1_rsa
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in user1_rsa.
Your public key has been saved in user1_rsa.pub.
The key fingerprint is:
SHA256:BJ5FGpGBCwM+Vw9769IACYHKoWD8gJURyYuSNOJQjUY user1
The key's randomart image is:
+---[RSA 2048]----+
|=OEB +==o |
|BBX =.=* |
|@*=B o+o. |
|*o+.o ... |
|. . .S |
| + |
| . o |
| . |
| |
+----[SHA256]-----+
同样方式生成user2_rsa
3、把user1_rsa_pub的内容上传到github后台, user2同样操作
https://help.github.com/articles/adding-a-new-ssh-key-to-your-github-account/
4、修改~/.ssh/config文件内容为:
#Default GitHub
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/user1_rsa
IdentitiesOnly yes Host github2
HostName github.com
User git
IdentityFile ~/.ssh/user2_rsa
IdentitiesOnly yes
5、添加你的ssh密钥到ssh-agent中
$ eval "$(ssh-agent -s)"
Agent pid 40672
$ ssh-add ~/.ssh/user1_rsa
Identity added: /c/Users/waston/.ssh/user1_rsa (/c/Users/waston/.ssh/user1_rsa)
$ ssh-add ~/.ssh/user2_rsa
Identity added: /c/Users/waston/.ssh/user2_rsa (/c/Users/waston/.ssh/user2_rsa)
6、测试
user1仓库测试:
cat@cat-pc MINGW64 /f/github/python (master)
$ ssh -T github.com
Hi user1! You've successfully authenticated, but GitHub does not provide shell access.
cat@cat-pc MINGW64 /f/github/python (master)
$ git push
Everything up-to-date

user2仓库测试:

$ ssh -T github2
Hi user2! You've successfully authenticated, but GitHub does not provide shell access.
cat@cat-pc MINGW64 /h/z8 (master)
$ git remote -v
origin git@github.com:user2/z.git (fetch)
origin git@github.com:user2/z.git (push)
cat@cat-pc MINGW64 /h/z8 (master)
$ git remote set-url origin git@github2:user2/z.git
cat@cat-pc MINGW64 /h/z8 (master)
$ git push
Everything up-to-date

其它:

#提示文件不存在,检查下rsa文件名或者重新生成key
$ ssh -T github2
no such identity: /c/Users/waston/.ssh/user2_rsa: No such file or directory
Permission denied (publickey).
 
参考:
Git 最著名报错 “ERROR: Permission to XXX.git denied ... - 简书
Quick Tip: How to Work with GitHub and Multiple Accounts
git - Using Multiple SSH Public Keys - Super User
Error: Permission to user/repo denied to user/other-repo - User Documentation
 
 

github多用户git push错误remote: Permission to user1/z.git denied to user2的更多相关文章

  1. Windows下解决github push failed (remote: Permission to userA/XXXX.git denied to userB.) 上传gitHub失败报错

    Windows环境下解决 github push failed (remote: Permission to userA/XXXX.git denied to userB.) · 初学GitHub的朋 ...

  2. git@github.com: Permission denied (publickey).////remote: Permission to xxx/test.git denied to xxx.等权限问题

    Error msg git@github.com: Permission denied (publickey) 或者: remote: Permission to xxx/test.git denie ...

  3. remote: Permission to user_name/Code.git denied to other_user_name. fatal: unable to access 'https://github.com/user_name/Code.git/': The requested URL returned error: 403

    Error msg: $ git push remote: Permission to xxx/Code.git denied to xxxxxx. fatal: unable to access ' ...

  4. git push是报Permission denied (publickey)错误解决

    今天晕了半天了,搞了个git工程到github上,以为很简单,因为之前也弄过,那知道搞了大半天都搞不好,一直报如下错误 D:\javawork\ee-0.0.1-SNAPSHOT>git pus ...

  5. git push错误解决方案

    错误提示: error: The requested URL returned error: 403 Forbidden while accessing https://nanfei9330@gith ...

  6. git push 错误,回滚 push操作

    作者:故事我忘了¢个人微信公众号:程序猿的月光宝盒 0.记一次使用git push后,覆盖了同事代码的糗事 前言: ​ 都在WebStorm中操作,Idea或者PyCharm同理 ​ 为了高度还原尴尬 ...

  7. Git push错误non-fast-forward后的冲突解决

    当要push代码到git时,出现提示: error:failed to push some refs to ... Dealing with “non-fast-forward” errorsFrom ...

  8. coding云进行git push报:permission denied

    1.原因可能是 登录其他的git 项目,本地缓存了其他用户的 用户名和密码 认证信息,导致一直权限不通过 解决: git remote add origin http://yourname:passw ...

  9. git解决 remote: Permission to wuheng1991/site-manager.git denied to XXX

    1.问题 2.解决 生成一个新的SSH KEY ssh-keygen  -t rsa –C “youremail@example.com” 命令: 3.修改 .git/config中的url 4.gi ...

随机推荐

  1. mac下导出kindle单词本的单词

    平常都是用kindle来看电子书,偶尔也会看上一些英文书籍,不可避免的会遇到不少陌生的单词,而kindle专门针对这种需求,做了不少优化,可以直接在kindle上面查阅单词,甚至可以背单词.但是毕竟不 ...

  2. hadoop系列一:hadoop集群安装

     转载请在页首明显处注明作者与出处 http://www.cnblogs.com/zhuxiaojie/p/6384393.html 一:说明 此为大数据系列的一些博文,有空的话会陆续更新,包含大数据 ...

  3. HDU 2520 我是菜鸟,我怕谁

    我是菜鸟,我怕谁 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  4. 【死磕Java并发】-----Java内存模型之happend-before

    在上篇博客([死磕Java并发]-–深入分析volatile的实现原理)LZ提到过由于存在线程本地内存和主内存的原因,再加上重排序,会导致多线程环境下存在可见性的问题.那么我们正确使用同步.锁的情况下 ...

  5. static的加载先后顺序

    1.静态变量的声明和赋值是分开的,静态变量会先被声明,赋值操做被放在了静态代码块中. 2.静态变量的赋值和静态代码块的执行顺序和代码的先后书写顺序相关. 3.静态代码块优先执行,其次构造方法,最后普通 ...

  6. C#表达式和语句

    表达式由操作数 (operand) 和运算符 (operator) 构成.表达式的运算符指示对操作数适用什么样的运算.运算符的示例包括+.-.*./ 和 new.操作数的示例包括文本.字段.局部变量和 ...

  7. phpcms 列表项 内容项

    根据上一篇内容继续 首页替换完成后 接下来替换列表页 首先把列表的静态网页放入相应模板的content文件夹下,并改名为 list.html 并且创建栏目时选择下面一项 同样,头尾去掉,利用{temp ...

  8. JavaScript中的this关键字的用法和注意点

    JavaScript中的this关键字的用法和注意点 一.this关键字的用法 this一般用于指向对象(绑定对象); 01.在普通函数调用中,其内部的this指向全局对象(window); func ...

  9. [Kafka] - Kafka内核理解:Message

    一个Kafka的Message由一个固定长度的header和一个变长的消息体body组成 header部分由一个字节的magic(文件格式)和四个字节的CRC32(用于判断body消息体是否正常)构成 ...

  10. 20150817---成长日记1---DelayQueue&&Delayed&&Other

    今天第一次接触DelayQueue,源于项目中的话单解析入库的拆分线程中引入,首先简单了解一下DelayQueue: DelayQueue是一个无界阻塞队列,只有在延迟期满时才能从中提取元素.该队列的 ...