背景:同一台电脑的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. [python]Python2编码问题

    以下内容说的都是 python 2.x 版本 简介 基本概念 Python "帮"你做的事情 推荐姿势 基本概念 我们看到的输入输出都是'字符'(characters),计算机(程 ...

  2. C++编程练习(8)----“二叉树的建立以及二叉树的三种遍历方式“(前序遍历、中序遍历、后续遍历)

    树 利用顺序存储和链式存储的特点,可以实现树的存储结构的表示,具体表示法有很多种. 1)双亲表示法:在每个结点中,附设一个指示器指示其双亲结点在数组中的位置. 2)孩子表示法:把每个结点的孩子排列起来 ...

  3. Eclipse 报java.lang.UnsupportedClassVersionError: ("yourclass") bad major version at offset=6

    报这个错误是指你的jar包或者class 的被编译的jdk版本比当前runtime的jdk版本高. 解决问题 1)如果是jar包,重新用jdk 1.6编译你的jar 包 2)如果是java文件或者项目 ...

  4. JAVA传值与传址

    要了解JAVA中的传值与传址问题,必要先要了解JVA中的栈内存和堆内存,>>>>点些查看<<<<昨天写的学习记录 栈:基本数据类型.数据的引用变量,这两 ...

  5. (2)java程序走一遍工作流activiti

    工作流从流程定义到创建一个流程实例完成执行步骤 使用activi-designer创建一个流程定义(.bpmn结尾的文件) 将定义好的流程定义和生成的png图片通过RepositoryService( ...

  6. Activity启动过程分析

    Android的四大组件中除了BroadCastReceiver以外,其他三种组件都必须在AndroidManifest中注册,对于BroadCastReceiver来说,它既可以在AndroidMa ...

  7. Codeforces Round #396 (Div. 2)

    C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...

  8. python - bilibili(三)wireshark分析

    当我们开始打开浏览器,并进入B站直播网页前,我们打开wireshark软件(软件的下载与安装请百度一下)开始截取当前数据. 然后输入直播间网址,enter进入就可以停止截取数据了,然后我们分析所截取的 ...

  9. 有关HTTP的粗读

    .mytitle { background: #2B6695; color: white; font-family: "微软雅黑", "宋体", "黑 ...

  10. V3学院XILINX FPGA寒假班培训感受 江苏大学 电子信息科学与技术 邓普建

    事先申明一点,我是大一的学生,因此会站在一个新生的角度叙述. 刚开始接触V3学院是在江苏大学与V3学院合办的FPGA/SOC培训中,那是对全校开放的免费培训,历时三个周末.我那时有幸从头听到了尾,觉得 ...