简体   繁体   English

当我在同一台计算机上使用多个 github 帐户推送时,git 上发生错误,即使我设置了 SSH

[英]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.

相关问题 同一台计算机上的多个 GitHub 帐户? - Multiple GitHub accounts on the same computer? 我需要帮助更改计算机上 Git 中的 GitHub 帐户 - I need help changing GitHub accounts in Git on my computer 如何使用 git 从我的 PC 推送到多个 GitHub 帐户? (不同的存储库) - How can I push to multiple GitHub accounts from my PC using git? (different repositories) 如何在同一台计算机上使用两个Git帐户? - How do I use two Git accounts on the same computer? 当我尝试使用集成的 git 将更改推送到我的 Github 存储库时,VS Code 给我一个 ssh_askpass 错误 - VS Code gives me an ssh_askpass error when I try to push the changes to my Github repository using the integrated git 如果我在两个帐户上都有相同的 SSH 密钥,我 git 克隆的仓库是否会使用这些凭据自动推送? - Does the repo I git clone automatically push using those credentials if I have same SSH key on both accounts? 我如何为 github 设置到我的计算机的 ssh? - How can i set up the ssh to my computer for github? Git:当我将不同的代码从不同的计算机“推送”到同一远程分支时,会发生什么? - Git: What happens when I “push” different code from different computers to the same remote branch? 我收到此错误 git@github.com: Permission denied (publickey), 当我在新 Mac 上 git push 时 - I get this error git@github.com: Permission denied (publickey), when I git push on new mac 如何在 Powershell 中使用 SSH 密钥推送到两个不同的 GitHub 帐户? - How do I push to two different GitHub accounts using SSH keys in Powershell?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM