Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Fix "Permission denied (publickey)" error when pushing with Git

"Help, I keep getting a 'Permission Denied (publickey)' error when I push!"

This means, on your local machine, you haven't made any SSH keys. Not to worry. Here's how to fix:

  1. Open git bash (Use the Windows search. To find it, type "git bash") or the Mac Terminal. Pro Tip: You can use any *nix based command prompt (but not the default Windows Command Prompt!)
  2. Type cd ~/.ssh. This will take you to the root directory for Git (Likely C:\Users\[YOUR-USER-NAME]\.ssh\ on Windows)
  3. Within the .ssh folder, there should be these two files: id_rsa and These are the files that tell your computer how to communicate with GitHub, BitBucket, or any other Git based service. Type ls to see a directory listing. If those two files don't show up, proceed to the next step. NOTE: Your SSH keys must be named id_rsa and in order for Git, GitHub, and BitBucket to recognize them by default.
  4. To create the SSH keys, type ssh-keygen -t rsa -C "". This will create both id_rsa and files.
  5. Now, go and open in your favorite text editor (you can do this via Windows Explorer or the OSX Finder if you like, typing open . will open the folder).
  6. Copy the contents--exactly as it appears, with no extra spaces or lines--of and paste it into GitHub and/or BitBucket under the Account Settings > SSH Keys. NOTE: I like to give the SSH key a descriptive name, usually with the name of the workstation I'm on along with the date.
  7. Now that you've added your public key to Github and/or BitBucket, try to git push again and see if it works. It should!

More help available from GitHub on creating SSH Keys and BitBucket Help.

Copy link

ecg-sniper commented Feb 6, 2022

This time I have to spend a minute to thank you for the good explanation.

Copy link

mariaclarahl commented Feb 18, 2022

Works for me, thank you very much!

Copy link

nielvid commented Feb 19, 2022

Copy link

rollanda21 commented Feb 21, 2022

Thanks a lot! This worked for me.

Copy link

ekjamu commented Mar 3, 2022

Thank you

Copy link

johannesrave commented Mar 5, 2022

Didn't work for me unfortunately. I'm still being asked to enter my ssh passphrase on WSL2.

Copy link

thirrukumar commented Mar 7, 2022

No solution for me. Finally it works after deleting contents in config file in .ssh.

Copy link

NickDulvy commented Mar 12, 2022

Adam, This solved a lot of github woes for me. Thanks.

Copy link

malikmukhtar commented Mar 16, 2022

It works, Thanks

Copy link

centratelemedia commented Mar 17, 2022

my problem solve here, thanks

Copy link

rocketxl5 commented Mar 24, 2022

It worked! Thank you

Copy link

albuquerque-rafael commented Mar 28, 2022


Copy link

Naboum commented Apr 5, 2022

You're a life savior, thank you

Copy link

Gio-Ayiman commented Apr 11, 2022

Thanks guy!

Copy link

nhut3110 commented Apr 18, 2022

thank you, it worked for me!

Copy link

berkayalan commented Apr 29, 2022

Thanks you, it also worked to me!

Copy link

jharris-uncomn commented May 5, 2022

VERY helpful for this noob. Thanks!

Copy link

gconnect commented May 8, 2022

Thanks. This worked for me

Copy link

9h057 commented May 11, 2022

Face palm. Thanks worked like a charm.

Copy link

OscarGabriel07 commented May 21, 2022

¡Funcionó, muchas gracias!

Copy link

nelsonpoon commented May 24, 2022

Thanks. This worked for me.

Copy link

vaniswamy commented May 25, 2022

Thanks. great help.

Copy link

mr-new-0509 commented May 25, 2022

Awesome! I appreciate you.

Copy link

jemilehin commented Jun 30, 2022

Thanks! worked for me.

Copy link

Xylopyrographer commented Jul 2, 2022

FWIW, on macOS, also need to add the private key to the SSH Agent as per this stack overflow link

By doing this in terminal:
ssh-add --apple-use-keychain ~/.ssh/id_rsa

(Note the command above is different from that provided in the link. It jhas been updated to reflect current version of ssh-add.)

Copy link

nbomasi commented Jul 5, 2022

Thanks, it solve my issue

Copy link

pauGuarch commented Jul 6, 2022

After trying many different solutions this one finally worked. Thanks a lot!

Copy link

knkailash commented Jul 6, 2022

Works like a charm, many thanks for this solution suggestion.

Copy link

shazib2022skipq commented Jul 7, 2022

Bro, youre a lifesaver. I wasted so much time on setting up the credential manager, but finally your post helped me figure this out. Thanks a lot and lots of love.

Copy link

pbatsaihan commented Aug 3, 2022


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment