[英]Error happens on git when I push with multiple github accounts on the same computer, even after I set SSH
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:我创建了一个新的 git 本地存储库,我第一次尝试使用git push origin master
进行推送,但我发现了以下错误:
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.
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 帐户时发生的常见情况,而这正是我正在做的事情。
I've already tried the common solution of setting SSH for all the github accounts I have in my computer.我已经尝试过为我计算机中的所有 github 帐户设置 SSH 的通用解决方案。 I made the directory of .ssh
and set the required files like this:我创建了.ssh
的目录,并像这样设置所需的文件:
.ssh/
├ config
├ id_myGithubAccount1_rsa
├ id_myGithubAccount1_rsa.pub
├ id_myGithubAccount2_rsa
├ id_myGithubAccount2_rsa.pub
└ known_hosts
id_myGithubAccountX_rsa
is of course the RSA secret key of myGithubAccountX
(X = 1,2) and .pub
is the public key of it. id_myGithubAccountX_rsa
当然是myGithubAccountX
(X = 1,2) 的 RSA 密钥, .pub
是它的公钥。
The content of config
file is as following: 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
The content of "known_hosts" is as following: “known_hosts”的内容如下:
github.com,13.114.40.48 ssh-rsa [Many characters] ==
52.69.186.44 ssh-rsa [many characters]==
After that, I tried to use git of myGithubAccount2
with the commands below:之后,我尝试通过以下命令使用 myGithubAccount2 的myGithubAccount2
:
git remote add origin git@github.com:<ACCOUNT_NAME>/<YOUR_REPSITORY>.git
and和
$ git config --global user.name "<YOUR_NAME>"
$ git config --global user.email <YOUR_EMAIL>
Then, I put ssh -T github-myGithubAccount2
and I've got the message below:然后,我输入ssh -T github-myGithubAccount2
并收到以下消息:
Hi myGithubAccount2! You've successfully authenticated, but GitHub does not provide shell access.
Many articles in the Web say this is all and we can use git of myGithubAccount2
. Web 中的许多文章都说这就是全部,我们可以使用 myGithubAccount2 的myGithubAccount2
。 However, the result is the beginning of this question.然而,结果是这个问题的开始。
What is wrong?怎么了?
I tried to use git of myGithubAccount2 with the commands below:我尝试通过以下命令使用 myGithubAccount2 的 git:
git remote add origin git@github.com:<ACCOUNT_NAME>/<YOUR_REPSITORY>.git
That does not use myGithubAccount2
那不使用myGithubAccount2
git remote set-url origin github-myGithubAccount2:<ACCOUNT_NAME>/<YOUR_REPSITORY>.git
That would use the right key.那将使用正确的键。
It needs to use the exact Host
entry 'github-myGithubAccount2' from the ~/.ssh/config
file.它需要使用~/.ssh/config
文件中的确切Host
条目“github-myGithubAccount2”。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.