当我在同一台计算机上使用多个github帐户推送时,即使在设置SSH之后,git上也会发生错误 [英] Error happens on git when I push with multiple github accounts on the same computer, even after I set SSH

查看:95
本文介绍了当我在同一台计算机上使用多个github帐户推送时,即使在设置SSH之后,git上也会发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个新的git本地存储库,并尝试尝试与 git push origin master 一起进行推送,但是我发现了以下错误:

I made a new git local repository and I tried to do push with git push origin master for the first time, but I caught the error below:

Warning: Permanently added the RSA host key for IP address '52.192.72.89' to the list of known hosts.
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

根据我的搜索,这似乎是最常见的情况,当人们尝试在一台计算机上使用多个github帐户时,这正是我正在做的事情.

According to my searching, it seems this is the common case which happens when one tries to use multiple github accounts in one computer machine, and that's exactly what I'm doing.

我已经尝试了为计算机上所有github帐户设置SSH的通用解决方案.我创建了 .ssh 的目录,并设置所需的文件,如下所示:

I've already tried the common solution of setting SSH for all the github accounts I have in my computer. I made the directory of .ssh and set the required files like this:

.ssh/
 ├ config
 ├ id_myGithubAccount1_rsa
 ├ id_myGithubAccount1_rsa.pub
  ├ id_myGithubAccount2_rsa
 ├ id_myGithubAccount2_rsa.pub  
 └ known_hosts

id_myGithubAccountX_rsa 当然是 myGithubAccountX 的RSA密钥(X = 1,2),而 .pub 是它的公钥.

id_myGithubAccountX_rsa is of course the RSA secret key of myGithubAccountX (X = 1,2) and .pub is the public key of it.

config 文件的内容如下:

Host github-myGithubAccount1
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/id_myGithubAccount1_rsa
  


Host github-myGithubAccount2
  User git
  Port 22
  HostName github.com
  IdentityFile ~/.ssh/id_myGithubAccount2_rsa

"known_hosts"的内容如下:

The content of "known_hosts" is as following:

github.com,13.114.40.48 ssh-rsa [Many characters] ==
52.69.186.44 ssh-rsa [many characters]==

之后,我尝试通过以下命令使用 myGithubAccount2 的git:

After that, I tried to use git of myGithubAccount2 with the commands below:

git remote add origin git@github.com:<ACCOUNT_NAME>/<YOUR_REPSITORY>.git

$ git config --global user.name "<YOUR_NAME>"
$ git config --global user.email <YOUR_EMAIL>

然后,我放入 ssh -T github-myGithubAccount2 ,我得到以下消息:

Then, I put ssh -T github-myGithubAccount2 and I've got the message below:

Hi myGithubAccount2! You've successfully authenticated, but GitHub does not provide shell access.

网络上的许多文章都说完了,我们可以使用 myGithubAccount2 的git.但是,结果就是这个问题的开始.

Many articles in the Web say this is all and we can use git of myGithubAccount2. However, the result is the beginning of this question.

怎么了?

推荐答案

我尝试通过以下命令使用myGithubAccount2的git:

I tried to use git of myGithubAccount2 with the commands below:

git remote add origin git@github.com:<ACCOUNT_NAME>/<YOUR_REPSITORY>.git

不使用 myGithubAccount2

git remote set-url origin github-myGithubAccount2:<ACCOUNT_NAME>/<YOUR_REPSITORY>.git

那将使用右键.

它需要使用〜/.ssh/config 文件中确切的 Host 条目'github-myGithubAccount2'.

It needs to use the exact Host entry 'github-myGithubAccount2' from the ~/.ssh/config file.

这篇关于当我在同一台计算机上使用多个github帐户推送时,即使在设置SSH之后,git上也会发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆