Git: git@gitlab.com: Permission denied (publickey) with VSC šŸ˜­

Hi, Iā€™m using Visual Code Studio on mac. I donā€™t know why, but I now get an error Git: git@gitlab.com: Permission denied (publickey). when I try to push. I went through the Generating a new SSH key pair section on this page again, generated a new ssh key. I added it to my gitlab. I just donā€™t know what my next step is supposed to be or how I can check if everything is set up all right. FYI, I really am a newbie!

Thanks for the help!

Hi,

Can you please share the exact steps you did, including the location of the generated ssh key pair? Also, which public key did you add to your gitlab.com profile?

Cheers,
Michael

1 Like

Hi @dnsmichi, I

  1. Opened terminal
  2. ssh-keygen -t ed25519 -C "bonjour@jolinmasson.com"
  3. Pressed enter to use the default path.
  4. Overwrited the current one y
  5. Entered a passphrase (twice for verification)

From there, I

  1. Entered pbcopy < ~/.ssh/id_ed25519.pub
  2. Pasted the key in GitLab settings, starting with ssh-ed25519 and ending with bonjour@jolinmasson.com
  3. Tested the setting with ssh -T git@gitlab.com
  4. Had the answer Welcome to GitLab, @JolinM!

Did I forget something?

1 Like

Hi,

thanks for sharing. I just wanted to make sure that all steps are taken and verified. This is a common source for errors.

Maybe VSCode caches the SSH key, e.g. did you close and restart the app once?

Cheers,
Michael

Hi again, I deleted my whole ~/.ssh folder and did all the again. Tried closing/reopening the app. I also tried while using Github Desktop, but it doesnā€™t work. :pensive:

Hereā€™s Github Desktop error message
Capture dā€™Ć©cran, le 2020-01-06 Ć  11.11.04

No idea unfortunately. I have stopped using SSH a while ago and am only using https auth tokens stored in my security key chain. The same should work with VS Code e.g. with adding the git clone httpsā€¦ command being asked for the credentials just once.

Cheers,
Michael

I wouldnā€™t mind using https auth tokens instead. After 10 minutes browsing the internet, I have no idea how tough. Would you have a source explaining how I can switch it?

  1. Personal auth token: https://docs.gitlab.com/ee/user/profile/personal_access_tokens.html
  2. git clone https://server/group/repo.git - insert username and auth token string

Step 2 can happen in VS Code but I suggest to do it on the command line in your desired project location.

Cheers,
Michael

1 Like

I just tried some other stuff. If I

  1. cd my/folder
  2. git push
  3. enter my passphrase
  4. IT WORKS!

But still gives the same error in GitHub Desktop or VisualCode Studioā€¦ :tired_face:

So youā€™re using an SSH key passphrase?

Well, recreating the SSH key without a passphrase resolved the issue!

Thanks for the tips @dnsmichi :wink:

1 Like

Hi!

Itā€™s most likely becuase your SSH key wasnā€™t ā€œunlockedā€.

On Mac after creating an SSH key you can add it to the keychain with:

ssh-add -K ~/.ssh/[your-private-key]

And in ~/.ssh/config you add:

Host *
  UseKeychain yes
  AddKeysToAgent yes
  IdentityFile ~/.ssh/[your-private-key]

So it knows where to look, and this will also make it so you donā€™t need to enter the passphrase each time, and thus VSCode is allowed to use they key, cause itā€™s unlocked not just when youā€™re pushing through CLI.

4 Likes

That must have been it; It now totally works!
Thanks for the help @helge :upside_down_face:

Nice, thanks for sharing. Learned something new today :heart:

1 Like

HiHelge,

I have the same problem, but I have Windows 10.

If I useā€¦

ssh-add -K ~/.ssh/id_rsa

I get the answer:

Could not open a connection to your authentication agent.

Can you help me with that?

Cheers Shushu

1 Like

Thatā€™s most likely because your ssh-agent isnā€™t running.
What are you using as a CLI?
WSL, GitBash, Powershell?

This article has a lot of different ways of enabling your ssh-agent depending on your terminal prompt.

To enable SSH Agent automatically on Windows, start a local Administrator PowerShell and run the following commands:

Yes,i am using Git Bash. ItĀ“s true vsCode canĀ“t connect to agentā€¦ I tested it in the vsCode terminal by using

ssd-add -l.

I tryed to setup the SSH Agent by this tutorial: https://code.visualstudio.com/docs/remote/troubleshooting#_fixing-ssh-file-permission-errors

It doenĀ“t work because i dont have the admine rights.

Do i have ony other idears?

Try

ssh-agent -s

i already did it - i get this answer:

canĀ“t download keys without provider

i also open ssh-agent.cmd in my Git folder and entered my passphrase. It didnĀ“t help.

on this point i stuck nowā€¦ :confused:

Thatā€™s is worked for me.Thank you

1 Like