![](/img/trans.png)
[英]Multiple github accounts with multiple SSH keys resulting in multiple contributors
[英]Getting 'repository not found' when using multiple ssh keys / github accounts
我一直在使用以下设置来在多个 ssh 密钥和 github 帐户之间切换。
首先,我在 .ssh/ 中有两个键
id_rsa_work
id_rsa_work.pub
id_rsa_personal
id_rsa_personal.pub
以及这些键的配置
Host personal
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_personal
Host work
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_work
然后我可以通过执行在帐户之间切换
ssh -T work
或ssh -T personal
然后我使用两个 gitconfig 文件来自动获取 git 配置。
~/.gitconfig
[user]
name = hex6b
email = kaigo@personal.com
[includeIf "gitdir:~/work/"]
path = ~/work/.gitconfig
~/work/.gitconfig
[user]
name = My work name
email = my.name@work.com
工作设置似乎工作正常,但是个人设置不允许我克隆新的存储库或推/拉现有的存储库。
错误:未找到存储库。 致命:无法从远程存储库读取。
请确保您拥有正确的访问权限并且存储库存在。
不知道为什么它突然不起作用,也许是因为 github 引入了个人访问令牌。
当我执行ssh-add -l
时,我也可以看到两个键,所以我不需要将它们添加到 ssh 代理中。
我需要对来自 github 的 url 做任何特别的处理吗? 通常我只是从代码对话框中复制它们。
是的,您确实需要更改 URL。 Git FAQ 解释了如何通过在每种情况下更改 URL来执行此操作。
他们给出的示例配置如下所示:
# This is the account for author on git.example.org.
Host example_author
HostName git.example.org
User git
# This is the key pair registered for author with git.example.org.
IdentityFile ~/.ssh/id_author
IdentitiesOnly yes
# This is the account for committer on git.example.org.
Host example_committer
HostName git.example.org
User git
# This is the key pair registered for committer with git.example.org.
IdentityFile ~/.ssh/id_committer
IdentitiesOnly yes
在这种情况下,主机git.example.org
是example_author
或example_committer
而不是git.example.org
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.