2

Fixed: (vscode) Git pull permission denied (Public key) on Mac OS

If you're using Mac OS (High Sierra or otherwise) you might have seen this error when you tried to push git code (to GitHub), especially if you tried doing so from something such as Visual Studio Code (vscode):

Thankfully, the solution is extremely simple. All you have to do is create (or edit) a ~/.ssh/config file and add the following:

And then run your SSH command(s) again. It also helps if you're using ssh-agent.

Why the error happens in the first place?

For whatever reason, at least in my case, VSCode wasn't able to detect and use the correct SSH details. So instead of using my proper Github login details that I was using via SSH keys and passphrases and all, it was trying to use the generic default “git@github.com” login. Well of course that's not going to be able to push nor sync or anything for a private repo!

The solution basically says that for any (*) hosts add the keys to ssh agent, use the MacOS keychain (so that it's all globally available especially to picky applications) and use this (~/.ssh/id_rsa) specific keyfile (which is locked behind a passphrase for good measure).

If this worked for you, let us know. If it didn't work for you, also let us know and let's see if we can find a solution that does.

  • Muzical says:

    I went from “Invalid credentials were supplied. Aborting operation.”” to “Invalid credentials were supplied. Aborting operation.
    Version control operation failed: ” after doing this 🙁

    • Piotr Krzyzek says:

      Oh noes, that’s no good.

      It’s essentially still saying the same thing. So first things to check:

      Have you setup ssh-agent?

      If so, then also remember to add both your own id_rsa to github but to also make sure VSCODE isn’t for some reason using it’s own key. IF it is, they you’ll have to add that one as well.

      How do you check if VSCODE has / is-using it’s own? Sadly that one is above my pay grade a bit. I do know there’s a way because I did connect it previously somehow. Sorry that I can’t be of much help on this specific 2nd item.

      Though, try first checking to see if your keys are added to Github and that you have ssh-agent setup, configured and running.

  • >