I was trying to push to Github from VSCode when I got the following error:
[email protected]: Permission denied (publickey). fatal: Could not read from remote repository.
I am not really sure what happened since I hadn’t changed anything. The only thing I can think of is I installed SourceTree, but I don’t remember messing with any of my settings. Anyways this is how I fixed this “Permission denied (publickey)” error.
Open your terminal and do
ls. You should see id_rsa and id_rsa.pub. My issue was that those files were not there anymore. To create those files, do step 3:
Open the file
id_rsa.pub. If you have VSCode, you can just do
code id_rsa.pub(explained here), and it opens the file in VS Code. Otherwise, you can do
vim id_rsa.pub. (you can exit out of vim by typing
Copy everything you see (make sure you don’t copy any extra spaces).
Go to github.com -> Settings -> SSH and GPG Keys https://github.com/settings/keys. Click “New SSH Key”. Give it a title and paste in the key. Finally, click “Add SSH Key”.
That’s it. Try git push again, and it should work.