0

I have two private GitHub repositories and two respective deploy keys on them with write access. For the first repository everything works well but for the second I always obtain:

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

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

If I check my loaded keys with:

ssh-add -E md5 -l

I can see that the fingerprints of the two keys are the same that in their respective GitHub Deploy keys page. So why I cannot push to the second repository?

phd
  • 82,685
  • 13
  • 120
  • 165
Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240

2 Answers2

2

I had exactly the same problem.

According to Github deploy keys: How do I authorize more than one repository for a single machine?

"Git will use the first matched hostname (ie. github.com), therefore only work properly for the first listed Host in the config file."

I found this solution : https://blog.harveydelaney.com/configuring-multiple-deploy-keys-on-github-for-your-vps/

The procedure is to modify the file .ssh/config to

Host repository-one
  Hostname github.com
  User git
  IdentityFile ~/.ssh/key-one
Host repository-two
  Hostname github.com
  User git
  IdentityFile ~/.ssh/key-two

And change in both repositories in the files .git/config the url of the remote

git@github.com:HarveyD/repository-one.git

by

repository-one:HarveyD/repository-one.git

And then I could do git pull in both repositories.

Pyjala
  • 38
  • 6
0

If I run:

ssh -T git@github.com

I see that I'm authentified with the deploy key of the first repository.

To push to the second repository, I have to unload all keys with:

ssh-add -D

and add back the key of the second repository.

Then I can push to the second repository.

Ortomala Lokni
  • 56,620
  • 24
  • 188
  • 240