简体   繁体   English

使用多个 ssh 密钥/github 帐户时获取“未找到存储库”

[英]Getting 'repository not found' when using multiple ssh keys / github accounts

I've been using the following setup for a while to switch between multiple ssh keys and github accounts.我一直在使用以下设置来在多个 ssh 密钥和 github 帐户之间切换。

Firstly I have two keys in .ssh/首先,我在 .ssh/ 中有两个键

id_rsa_work
id_rsa_work.pub
id_rsa_personal
id_rsa_personal.pub

And a config for those keys以及这些键的配置

Host personal
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_personal

Host work
   HostName github.com
   User git
   IdentityFile ~/.ssh/id_rsa_work

And then I'm able to switch between accounts by doing然后我可以通过执行在帐户之间切换

ssh -T work or ssh -T personal ssh -T workssh -T personal

and then I use two gitconfig files to auto pickup the git config.然后我使用两个 gitconfig 文件来自动获取 git 配置。

~/.gitconfig ~/.gitconfig

[user]
    name = hex6b
    email = kaigo@personal.com

[includeIf "gitdir:~/work/"]
    path = ~/work/.gitconfig

~/work/.gitconfig ~/work/.gitconfig

[user]
        name = My work name
        email = my.name@work.com

The work setup seems to work fine, however the personal one will not allow me to clone new repos or push/pull existing repos.工作设置似乎工作正常,但是个人设置不允许我克隆新的存储库或推/拉现有的存储库。

ERROR: Repository not found.错误:未找到存储库。 fatal: Could not read from remote repository.致命:无法从远程存储库读取。

Please make sure you have the correct access rights and the repository exists.请确保您拥有正确的访问权限并且存储库存在。

Not sure why it's suddenly not working, maybe since github introduced personal access tokens .不知道为什么它突然不起作用,也许是因为 github 引入了个人访问令牌

I can also see both keys when I do a ssh-add -l so I don't need to add them to the ssh agent.当我执行ssh-add -l时,我也可以看到两个键,所以我不需要将它们添加到 ssh 代理中。

Do I need to do anything special with the urls from github?我需要对来自 github 的 url 做任何特别的处理吗? Usually I just copy them from the code dialog.通常我只是从代码对话框中复制它们。

在此处输入图片说明

Yes, you do need to change the URLs.是的,您确实需要更改 URL。 The Git FAQ explains how to do this by changing the URL in each case. Git FAQ 解释了如何通过在每种情况下更改 URL来执行此操作

The example configuration they give looks like this:他们给出的示例配置如下所示:

# 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

In this case, the hostname would be example_author or example_committer instead of git.example.org .在这种情况下,主机git.example.orgexample_authorexample_committer而不是git.example.org

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM