2

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)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
ChristianOConnor
  • 820
  • 7
  • 29

1 Answers1

1

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)

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Thanks for the the help and there's a lot of great information here. but for some reason vscode stopped letting me use ssh at all. Now when I try to clone a repo in the first place it just gives me the error "cannot spawn --get-all: No such file or directory" and "fatal: unable to fork" when I try to initially clone my repositories. My command is "git clone git@gitlab.com/.../...git" Lol git and ssh are really not cooporating with me today. – ChristianOConnor Apr 08 '20 at 10:01
  • @ChristianOConnor Check the %PATH% used when you are launching VSCode. Maybe Git is not correctly referenced there. I use typically a simplified path as in here: https://stackoverflow.com/a/58254413/6309 – VonC Apr 08 '20 at 10:08
  • I don't think it's a %PATH% issue. I'm using vscode with cmder's bash terminal (git for windows terminal) and I can do `git clone https://gitlab.com/.../...git` and clone the repo just fine, but for some reason when the command is `git clone git@gitlab.com/.../...git` instead of `git clone https://gitlab.com/.../...git` it fails. – ChristianOConnor Apr 09 '20 at 09:01
  • 1
    @ChristianOConnor What does `set|grep -i ssh` returns? Do you have any "ssh" environment variable? – VonC Apr 09 '20 at 09:03
  • wow, it returned a ton of stuff but I think the relevant things you're looking for are `/c/Windows/System32/OpenSSH` `PLINK_PROTOCOL=ssh` I think the problem lies in `/c/Windows/System32/OpenSSH` right? I want to use cmder's version of ssh aka `/usr/bin/ssh` not `/c/Windows/System32/OpenSSH` One other thing that's weird is when I type `which ssh` I get `/usr/bin/ssh` – ChristianOConnor Apr 09 '20 at 20:45
  • PLINK? last tile I saw it, it was 2012: https://stackoverflow.com/a/11273633/6309. No `GIT_SSH`? – VonC Apr 09 '20 at 20:46
  • wow, it returned a ton of stuff but I think the relevant things you're looking for are /c/Windows/System32/OpenSSH PLINK_PROTOCOL=ssh I think the problem lies in /c/Windows/System32/OpenSSH right? I want to use cmder's version of ssh aka /usr/bin/ssh not /c/Windows/System32/OpenSSH One other thing that's weird is when I type which ssh I get /usr/bin/ssh – ChristianOConnor Apr 09 '20 at 20:50
  • Also no `GIT_SSH` – ChristianOConnor Apr 09 '20 at 20:50
  • Not sure. I use the ssh coming with git, which is why I always set a simplified path, as suggested before. – VonC Apr 09 '20 at 21:07
  • I tried to manually set the GIT_SSH path. I did `export GIT_SSH="/usr/bin/ssh"` and that still gave me the same error. BTW I get this error even when I try to clone in a cmder terminal outside of vscode. Any thoughts? – ChristianOConnor Apr 13 '20 at 09:50
  • 1
    @ChristianOConnor As I mentioned, the first test is try a CMD session with a simplified PATH: https://stackoverflow.com/a/58254413/6309 – VonC Apr 13 '20 at 12:22
  • I tried a version of your post slightly modified for a bash terminal: I opened vscode and used the bash terminal (within vscode) to run `export PATH=/c/Windows/System32:/c/Windows:/c/Windows/System32/wbem:/c/Windows/System32/WindowsPowerShell/v1.0/` `export GH=/mingw64/bin/git` `export PATH=$GH/bin:$GH/usr/bin:$GH/cmd:$GH/mingw64/bin:$PATH` Then I ran `/mingw64/bin/git clone git@gitlab.com/../..git` and I got exactly the same error. `error: cannot spawn --get-all: No such file or directory error: cannot spawn --get-all: No such file or directory fatal: unable to fork` – ChristianOConnor Apr 13 '20 at 21:13
  • Just for testing, would that work in a CMD session? – VonC Apr 13 '20 at 21:16
  • Still won't work. I opend CMD and typed `PATH=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\WINDOWS\System32\WindowsPowerShell\v1.0\` `set GH=C:\tools\Cmder\vendor\git-for-windows` `set PATH=%GH%\bin;%GH%\usr\bin;%GH%\cmd;%GH%\mingw64\bin;%PATH%` `"C:\Program Files\Microsoft VS Code\Code.exe"` and I still got the same error when I tried `git clone git@gitlab.com/../..git` in the vscode terminal. Keep in mind my vscode terminal is still a bash terminal because I have vscode hartdcoded to use bash. I used a cmd windows to do every command before vscode was opened. – ChristianOConnor Apr 13 '20 at 22:00
  • @ChristianOConnor Did you relaunch VSCode from that CMD session? – VonC Apr 14 '20 at 05:03
  • @ChristianOConnor Does `ssh -T gitlab` works from the CMD with the simplified PATH? – VonC Apr 16 '20 at 09:21