1

Following different pages I ended up with a ~/.ssh/config looking like this:

Host github-personal
  HostName github.com
  IdentityFile ~/.ssh/one_key

Host github.com
  HostName github.com
  IdentityFile ~/.ssh/two_key

Host *
  UseKeychain yes
  AddKeysToAgent yes

It works fine but only on the first try on each repo after login. For example:

  1. Login

  2. Execute git pull on a repo with ssh one_key. Successful.

  3. Execute git pull on a repo with ssh two_key. Failed.

    ERROR: Repository not found. fatal: Could not read from remote repository.

    Please make sure you have the correct access rights and the repository exists.

Need to logout

  1. Login

  2. Execute git pull on a repo with ssh two_key. Successful.

  3. Execute git pull on a repo with ssh one_key. Failed.

    ERROR: Repository not found. fatal: Could not read from remote repository.

    Please make sure you have the correct access rights and the repository exists.

I can't get both of the keys working without logging out. Both are private repositories.

I'm using macOS Ventura 13.2 with M2.

Any ideas why this is happening?

2
  • Is this a problem with git or ssh? Can you post the exact error you received rather than “failed?”
    – Allan
    Jan 30, 2023 at 18:15
  • Edited adding the error message. My guess is that it has to do with macos config because i have the same ssh config on my linux distro without the UseKeychain and AddKeysToAgent params and works as expected.
    – Mooze
    Jan 30, 2023 at 18:28

1 Answer 1

1

I found out I was missing IdentitiesOnly yes. My final config looks like this:

Host github-personal
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519
  IdentitiesOnly yes

Host github.com
  HostName github.com
  IdentityFile ~/.ssh/id_ed25519_imp
  IdentitiesOnly yes

Host *
  UseKeychain yes
  AddKeysToAgent yes

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .