gitgithubgit-push

git@github.com: Permission denied (publickey)


I created a new remote repository and tried to use git push -u origin master command to push my local files into the new repository the first time after I add it and commit it. However, it pops up this git@github.com: Permission denied (publickey). fatal: Could not read from remote repository.. How can I fix this fatal error?

I've tried this
How to solve Permission denied (publickey) error when using Git? It seems that the question in this link happens in the first time using git. I've used my git for a while, do I still need to follow this solution? Can anyone gives me a more specific solution?

This the fatal error that I got

C:\Users\ASUS\Desktop\React-Practice App\my-app>git status
On branch master
nothing to commit, working tree clean

C:\Users\ASUS\Desktop\React-Practice App\my-app>git push -u origin master
git@github.com: Permission denied (publickey).
fatal: Could not read from remote repository.

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

Solution

  • You’re accessing GitHub through SSH. First generate an SSH key pair; then add the public key to GitHub.

    Generate key pair, github prefers the "Ed25519 algorithm"

    ssh-keygen -t ed25519 -C "your_email@example.com"
    

    It still allows using rsa for systems that don't support Ed25519

    ssh-keygen -t rsa -b 4096 -C “youremail@example.com”
    

    See more at https://help.github.com/en/articles/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent and https://help.github.com/en/articles/adding-a-new-ssh-key-to-your-github-account