Search code examples
gitgithubsshssh-keys

Why my GitHub deploy key is not used on my second private repository?


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?


Solution

  • 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.