Git looking for my SSH key in the wrong location

16,488

Solution 1

GitLab itself isn't looking for your ssh keys: as a client, you are using ssh to contact GitLab, which means only openssh is looking for those keys.

It (openssh) will find them in:

  • %HOME%\.ssh (so check what the environment variable HOME is set to)
  • %HOME%\.ssh\config (where an IdentifiyFile directive can set a custom path for the ssh private key, so check if you have a .ssh/config file)

The OP Neil Kelsey confirms in the comments that the %HOME%\.ssh\config was causing some kind of interference.

And the push url seemed still referencing an https url.
A simple git remote set-url --push origin <ssh/url> fixed that.

Solution 2

For macOS users, this problem can be fixed by running the following commands:

rm ~/.ssh/known_hosts # remove previous hosts
ssh-add -A # add all known SSH keys

After running the above commands, the problem should be fixed.

Share:
16,488
Neil Kelsey
Author by

Neil Kelsey

The queen honey bee has sex with on average 17-20 males in a single afternoon. Just like your mom.

Updated on June 04, 2022

Comments

  • Neil Kelsey
    Neil Kelsey almost 2 years

    I've been having a bit of a head ache with trying to pull down a repository held in Gitlab. This is all done in Windows 8.1 on a Ubuntu VM by the way if that helps. I've added my public key in Gitlab and added my private key to ssh-agent ... all seems correct.

    When I try and do a git pull this is where I run in to issues. It seems to me that Git is simply looking in the wrong location, my private key is stored in c/Users/Neil/.ssh but it seems as if git is looking in c/Users/Neil/.ssh/342/200/217 ...

    C:\Users\Neil\code\homestead>git pull
    no such identity: /c/Users/Neil/.ssh/id_rsa\342\200\217: No such file or directory
    [email protected]'s password:
    

    I've no idea why git would be looking there or am I thinking wrong about this? Can anyone shed some light on things for me?