Git: git@gitlab.com: Permission Denied (publickey) when I press "synchronize changes" button

Viewed 1345

I use windows and cmder and have the default terminal set to cmder's bash term (I believe it's whatever version of git-for-windows that ships with cmder).
I also have a password protected ~/.ssh/id_ed25519 ssh key file.

Here is my ~/.ssh/config file although I've tried almost every possible setting for this file already.

Host gitlab.com
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_ed25519`

I've also tried

Host *
HostName gitlab.com
User git
IdentityFile ~/.ssh/id_ed25519`

I have been working on this for a really long time now and it appear there's not really any good information out there on this topic. No matter how I set this up it always says "Git: git@gitlab.com: Permission Denied (publickey)" when I press the synchronize changes button in the lower left corner.

I have tried everything that I have found on a multitude of forums including making sure "remote.SSH.showLoginTerminal": is set to "true" and doing almost every possible configuration of ~/.ssh/config.

When I run "git pull" or "git push" from the terminal, it prompts me for the password to my keyfile and I type the password and it works fine.
For some reason whenever I hit that synchronize changes button I get the same error "Git: git@gitlab.com: Permission Denied (publickey)."

Also, I already have "ssh-agent" running and I have my keyfile added to ssh-agent as an identity. So when I type "ssh-add -l" it does give me the correct keyfile information.

So to summarize the key facts:

  1. When I run git pull/push/..., it promps me for my password and works fine
  2. When I press "Synchronize changes", it gives me the error message Git: git@gitlab.com: Permission Denied (publickey)
1 Answers

Check first the remote URL used by VSCode when it pull or push:
Ctrl+Shift+P: Git: show Git output

Double-check the remote URL used by your local repository

cd /path/to/repo
git remote -v

I would use as URL

git remote set-url origin gitlab.com:<me>/<myrepo>

No need for git@ since your ~/.ssh/config is supposed to provide it for you.
Actually, I would change in that ~/.ssh/config file the Host entry from gitlab.com to gitlab and:

git remote set-url origin gitlab:<me>/<myrepo>

That way, you are sure to be using the SSH config file.

I would also test the authentication with

ssh -T gitlab
ssh -Tvvv gitlab

(Use the second form only if the first fails)

Related