在开始之前,我应该说我已经阅读了很多关于这个问题的主题(列在本文结尾处),但没有一个为我工作,或者我在这里错过了一些微不足道的东西。如何通过SSH为两个不同的存储库设置两个不同的Github帐户?
起初,我使用HTTPS克隆了存储库,但随后我从here的文档切换到SSH。我确实生成了每个SSH密钥,并将其添加到ssh-agent
之后的文档从here。
在几行(使用假数据,~
意味着我的主目录),这是我做了什么:
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
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 "[email protected]"
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 = [email protected]: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
Note: The title may seem confusing but it is correct because it is what I want to achieve I am just talking about one example but at the end I should be able to setup more than one account pointing to different repositories.
可能重复多个bitbucket帐户的ssh配置 - 简单的例子,但'远端挂起意外'](https://stackoverflow.com/questions/14409761/ssh-config-for-multiple-bitbucket-帐户 - 简单例子 - 丁得到-远程) – Ikke