gitgithubssh

Dumb permission denied issue preventing me from cloning a simple repo


So I’m very embarrassed to be opening this question, but I actually can’t figure it out. I am having issues cloning a GitHub repo (yes, believe it or not…), yet I have followed all the necessary steps and have cloned repos many times before.

So… I have generated a new SSH key, as per githubs documentation: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

And I have added it to GitHub too (and yes, as a SSH key under SSH and GPG keys) - and yes, that was from catting the .pub file and pasting it in correctly.

I can even run ssh -T [email protected] and it returns You've successfully authenticated, but GitHub does not provide shell access.

So… when I try to clone the repo with the clone command (i.e. sudo git clone [email protected]:user/repo.git) via SSH, it asks for this:


Warning: the ECDSA host key for 'github.com' differs from the key for the IP address '140.82.121.4'
Offending key for IP in /root/.ssh/known_hosts:2
Matching host key in /root/.ssh/known_hosts:3
Are you sure you want to continue connecting (yes/no)?

To which I obviously say yes. Yet it then returns this error:

[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 also tried ssh-keygen -R github.com and ssh-keygen -R IP_ADDRESS as per other stack overflow threads, but nothing. I then deleted the known hosts file altogether and tried again, but nothing.

Can anyone tell me what’s the dumb thing I’m not doing right here?


Solution

  • ssh -T [email protected] and sudo git clone [email protected]:user/repo use different keys, because the first one is done as your regular user and the second is done as root.

    Remove sudo from the clone command, and both the clone and any future network operations on that repo (fetches, pulls, pushes, etc.) should work fine.