Home > OS >  Git is not using the correct SSH key to autheticate [closed]
Git is not using the correct SSH key to autheticate [closed]

Time:09-25

I have two repositories in two hosts. I recently configured ssh in GitHub github was working but not the "other" one. So I added the keys to ~/.ssh/config as follows.

Host other
    HostName other.host
    IdentityFile ~/.ssh/id_rsa
    User git

Host github
    HostName github.com
    IdentityFile ~/.ssh/id_ed25519
    User git

However now, git actions to "other" works but not GitHub.

I tried

I removed the know_hosts file and retried. Seems like ssh is using id_rsa key for "github.com"

$ git pull
The authenticity of host 'github.com (140.82.121.4)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])?yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
[email protected]: Permission denied (publickey).
fatal: Could not read from remote repository.

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

I tried restarting sshd

sudo systemctl restart sshd.service

CodePudding user response:

Note that when you declare config Host entries, those entries are now part of your URL.

In your case:

cd /path/to/local/repo
git remote set-url origin github:<me>/<myrepo>
                          ^^^^^^

You need to use the exact Host string you set in ~/.ssh/config: it is a shortcut for ssh -i ~/.ssh/id_ed25519 [email protected].

  • Related