-1

I am trying to push my project to a github repo created in my github account. When I try to push it, I get the following error:

git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.

I have generated an SSH key and added it to my github account. However, I'm still getting this error.

How do I successfully push my project to my github repo?

Ayan Dasgupta
  • 304
  • 1
  • 4
  • 11
  • Don't forget to start `ssh-agent` and `ssh-add your-ssh-key`. – kometen Aug 08 '22 at 20:28
  • 1
    Are you sure that you correctly added the SSH key? What output of the following command `ssh -T git@github.com`? – Pavlo Myroniuk Aug 08 '22 at 20:28
  • @PavloMyroniuk I am getting git@github.com: Permission denied (publickey) – Ayan Dasgupta Aug 08 '22 at 20:32
  • 1
    @AyanDasgupta then your problem in the SSH key. Because the output should look like this: "Hi ! You've successfully authenticated, but GitHub does not provide shell access.". How did you add your SSH key? Are you sure that you have copied the public key? Also, what operating system are you using? – Pavlo Myroniuk Aug 08 '22 at 20:35
  • @PavloMyroniuk I am using Windows 11. I generated an SSH key using ssh-keygen -t ed25519 -C "your_email@example.com" in my git bash. Then I copied the key starting with: ecdsa-sha2-nistp256 in the 'known hosts' file and added it in my github account. – Ayan Dasgupta Aug 08 '22 at 20:40
  • 2
    Try to copy the content of the generated `.pub` file instead of known_hosts. You can find an example here: https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account – Pavlo Myroniuk Aug 08 '22 at 20:45
  • @PavloMyroniuk Thank you very much :) copying the content of the .pub file solved the problem. – Ayan Dasgupta Aug 08 '22 at 20:54
  • https://stackoverflow.com/search?q=%5Bgit%5D+Permission+denied+publickey – phd Aug 08 '22 at 21:01

1 Answers1

1

Did you check your ssh connection to the github https://docs.github.com/en/authentication/connecting-to-github-with-ssh/testing-your-ssh-connection

And then check your remotes for that repo.

git remote -v 

And change remote to the ssh url

git remote set-url origin "your-ssh-url"
M.Said
  • 76
  • 4