我在两种情况下使用git:
首先,我用于ssh-keygen生成在OpenShift站点更新的密钥.这样的密钥存储在~/.ssh/和创建id_rsa和id_rsa.pub.
然后我开始从Github克隆一个存储库,我曾经ssh-keygen再次做过并开始推送,它工作正常.然后我克隆了另一个存储库并开始遇到问题:
克隆到第二个存储库时遇到问题.每次我尝试推动都会显示如下:
ERROR: Permission to diegoaguilar/cursoJava.git denied to diegoaguilar/cursoCannibalCreatures. fatal: The remote end hung up unexpectedly
但由于可以看出它diegoaguilar/cursoCannibalCreatures是不正确的,因为它是另一个存储库.
我甚至尝试删除这样的存储库目录,并再次克隆它,同样的事情发生了.
我已经得到了~/.ssh:
config:
Host cursoJava
Hostname github.com
User git
IdentityFile ~/.ssh/id_java
Host cursoCannibalCreatures
Hostname github.com
User git
IdentityFile ~/.ssh/id_cannibal
Host openshift
Hostname openshift.com
User git
IdentityFile ~/.ssh/openshift
Run Code Online (Sandbox Code Playgroud)
得到了:
id_cannibal id_cannibal.pub id_java id_java.pub known_hosts
Run Code Online (Sandbox Code Playgroud)
有些东西不喜欢id_openshift,id_openshift.pub但因为它不起作用,我现在不在乎.
我创造了这样的文件,他们是.pub通过ssh-keygen -f <filename>又给不同的密码短语每个.我.pub在每个Github存储库设置中添加了作为部署密钥的内容.
我究竟做错了什么?这应该怎么样?并且,当在另一台机器上工作时,如何正确获取这些密钥,证明它是我并透明地工作?
产量git remote -v:
origin git@github.com:diegoaguilar/cursoJava.git (fetch)
origin git@github.com:diegoaguilar/cursoJava.git (push)
origin git@github.com:diegoaguilar/cursoCannibalCreatures.git (fetch)
origin git@github.com:diegoaguilar/cursoCannibalCreatures.git (push)
Von*_*onC 47
正如在" ssh,github,它不起作用 "中所提到的,诀窍是不使用公共的默认id_rsa(.pub)名称:私钥(因为你只能定义其中的几个),但名称不同.
但是,只有当您以不同的用户身份访问这些存储库时才会这样
在您的情况下,您正在使用相同的用户访问repos ,并且一个ssh密钥就足够了.
请参阅" GitHub帮助 ":
此错误表示您推送的密钥作为部署密钥附加到另一个存储库,并且无权访问您尝试推送到的存储库.
要解决此问题,请从存储库中删除部署密钥,然后将密钥附加到您的用户帐户.
这是为两个不同的用户使用GitHub.
然后~/.ssh/config,您可以定义一个文件,在该文件中以完整路径引用每个私钥:
Host github1
HostName github.com
User git
IdentityFile ~/.ssh/id_repo1
Host github2
HostName github.com
User git
IdentityFile ~/.ssh/id_repo2
Run Code Online (Sandbox Code Playgroud)
而不是使用git@gihub.com:user/repo1,你会使用:
github1:user/repo1
Run Code Online (Sandbox Code Playgroud)
它使用键入Host' github1'来引用user(git),hostname(github.com)和要使用的确切私有/公共密钥 ~/.ssh/id_repo1(.pub)
因此,如果您有第二个使用存储的第二个密钥的回购~/.ssh/id_repo2(.pub),您需要使用github2上面定义的条目' '(您可以根据需要命名),然后更改您拥有的原始网址:
git remote set-url origin github2:user/repo2
Run Code Online (Sandbox Code Playgroud)
这样,a git push将使用正确的密钥(一个用于repo2)
如果不这样做,您将能够推送一个仓库(使用默认密钥 ~/.ssh/id_rsa(.pub),默认名称),但您将无法推送到第二个仓库,这需要一组不同的公钥/私钥.