2

I am working on windows 10 and I am trying to connect git via ssh with selfhosted(corporate) instance of gitlab. I try to follow guide here https://docs.gitlab.com/ee/ssh/. I am at the stage that ssh -Tv git@corpo.gitlab correctly logs me into the instance, however when I try to do git fetch gitlab ssh connection fails.

I have tried to compare debug output of standalone ssh invocation and git invoked ssh, and I have found out that in "git" variant, my private key is not even tried to be used. Logs says it looks in the correct user directory (so it is not an 'user scope' isse).

Why this can happen? I have added remote to the git repository via git remote gitlab git@corp.gitlab.

setting proper ssh config file with

 Host ssh.corpo.gitlab
     HostName ssh.corpo.gitlab
     IdentityFile ~/.ssh/my_corpo_key

fixes the issue, but I think it should work without those additional settings. What could make the difference ?

Antoniossss
  • 31,590
  • 6
  • 57
  • 99
  • 1
    Windows comes with its own `ssh`, and Git-for-Windows comes with *its* own `ssh`. The two implementations may not talk to each other properly. You can get Git to use the Windows ssh, although I don't know offhand what the right way to do that is. – torek Sep 14 '21 at 09:22
  • You are very correct, I just checked that windows uses OpenSSH_for_Windows8 + LibreSSL while git invoked OpenSSH8 + Openssl. Different binaries are beeing used,therfore I have added "default" key only to the "windows" instance. This explains (answers) my question actualy. – Antoniossss Sep 14 '21 at 09:39
  • @torek [`set GIT_SSH`](https://stackoverflow.com/a/8713121/7976758), e.g. – phd Sep 14 '21 at 09:41
  • @phd How does that compare to setting `GIT_SSH_COMMAND` or `core.sshCommand`? (In particular, do Windows users and/or ecosystems have their own environment variable overrides they use for special purposes?) – torek Sep 14 '21 at 12:20
  • @torek [`GIT_SSH`](https://git-scm.com/docs/git#Documentation/git.txt-codeGITSSHcode) must point to a binary (or a script) and doesn't accept parameters. `GIT_SSH_COMMAND` allows complex command line. I don't think Git-for-Windows has its own environment variables. – phd Sep 14 '21 at 12:47
  • I did not mean to ask if Git-for-Windows added even more environment variables to this list (although that's a fine question too :-) ), but rather things like: do 47 Windows IDEs export their own `GIT_SSH` and it's important for them to override this, which is why we recommend exporting `GIT_SSH` here? Or, do 12 IDEs export `GIT_SSH_COMMAND`, which overrides `GIT_SSH`, and the remaining 35 export nothing but should use your setting, in which case either one should be allowed, etc. That's the kind of ecosystem knowledge that determines which of all the various options is the "right" one. – torek Sep 14 '21 at 12:53

1 Answers1

0

I have added remote to the git repository via git remote gitlab git@corp.gitlab.

If you want to use your key, you would need a ~/.ssh/config with:

Host corpo.gitlab
  Hostname ssh.corpo.gitlab
  IdentityFile ~/.ssh/my_corpo_key
  User git

And the URL would become:

git remote set-url gitlab corpo.gitlab:<me>/<myrepo>
                          ^^^^^^^^^^^^
                   (need to match the Host entry)
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250