【发布时间】:2017-07-04 11:11:04
【问题描述】:
在开始之前,我应该说我已经阅读了很多关于这个问题的主题(列在这篇文章的末尾),但没有一个对我有用,或者我在这里遗漏了一些琐碎的东西。
起初我确实使用 HTTPS 克隆了存储库,但后来我按照 here 的文档切换到了 SSH。我确实根据here 的文档生成了每个 SSH 密钥并将它们添加到ssh-agent。
几行代码(使用假数据,~ 表示我的主目录)这就是我所做的:
$ ssh-keygen -t rsa -b 4096 -C "first@gmail.com"
Enter a file in which to save the key (~/.ssh/id_rsa): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
$ ssh-keygen -t rsa -b 4096 -C "second@gmail.com"
Enter a file in which to save the key (~/.ssh/id_rsa_second): [Press enter]
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
$ eval "$(ssh-agent -s)"
Agent pid 12697
$ ssh-add ~/.ssh/id_rsa
Identity added: ~/.ssh/id_rsa (~/.ssh/id_rsa)
$ ssh-add ~/.ssh/id_rsa_second
Identity added: ~/.ssh/id_rsa_second (~/.ssh/id_rsa_second)
$ ssh-add -l
4096 SHA256:gb+Gn4SqiyAP5ABUsmX6Xz11RHTSvDsWgEE5P2R2VTE ~/.ssh/id_rsa (RSA)
4096 SHA256:yxWMompayDNtYjv5y+FfJl7OpQ5Qu90kPgdXXvx6DRA ~/.ssh/id_rsa_second (RSA)
下一步是创建具有以下内容的~/.ssh/config 文件:
#first account
Host github.com-first
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa
#second account
Host github.com-second
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_second
我在这里停下来尝试一下,将id_rsa_second 的 SSH 发布密钥添加到我想使用它的存储库中(这不需要解释)。下一个git pull:
$ git pull
Bad owner or permissions on /home/rperez/.ssh/config
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
然后我尝试了以下方法:
-
将
.git/config文件更改为以下内容:[remote "origin"] url = git@github.com-second:repo/repo.git fetch = +refs/heads/*:refs/remotes/origin/*
但它不起作用,我的意思是我得到了与以前完全相同的错误。
我做错了什么?我错过了什么?
我读过的:
- How to properly configure ssh keys to multiple remote accounts involving github and bitbucket?
- GitHub: Multiple account setup
- Multiple github accounts on the same computer?
- Quick Tip: How to Work with GitHub and Multiple Accounts
- Can't get Multiple SSH keys to work for multiple github accounts
- Multiple SSH Keys settings for different github account
注意:标题可能看起来令人困惑,但它是正确的,因为这是我想要实现的目标。我只是在谈论一个示例,但最后我应该能够设置多个指向不同存储库的帐户。
【问题讨论】: