windowsgitpycharmgitlabssh-keys

Git does not use SSH key (Windows)


I created a SSH key for my GitLab repository and when I test it with SSH it does work and asks for the passphrase:

>ssh -T git@gitlab.lrz.de
Enter passphrase for key 'C:\Users\[username]/.ssh/id_ed25519':
Welcome to GitLab, @000[...]!

I also used

>git remote set-url origin git@gitlab.lrz.de:000[...]/project.git

without errors. However, when I try to commit and push to the repository, then Git asks for the Password of git@gitlab.lrz.de and not for the passphrase of the SSH key.

According to the Docs (https://docs.gitlab.com/ee/ssh/), you can set the ssh key in the config file ~/.ssh/config. So I created a text file in this directory with this content:

Host gitlab.lrz.de
 HostName gitlab.lrz.de
 IdentityFile ~/.ssh/id_ed25519

It still does not work and I am not sure if it even uses this config file. I was able to get everything running on a Linux server but not on this Windows computer. I tried it via command line and via Pycharm.

>git --version
git version 2.35.1.windows.1 

Solution

  • You can customize the ssh command used by git in the git config and then pass your key when using any git command.

    git config core.sshCommand "ssh -i ~/.ssh/id_ed25519"