go-git: ssh private key not being picked up

By default git pickups my ssh key from ~/.ssh, but for pull and push operations this fails for go-git.

Error: ssh: handshake failed: ssh: unable to authenticate, attempted methods [none publickey], no supported methods remain

If I do an ssh-add with my key it will start working.

This is on OSX.

About this issue

  • Original URL
  • State: open
  • Created 4 years ago
  • Reactions: 21
  • Comments: 16

Most upvoted comments

Got the same issue on macos as well

chmod 600 ~/.ssh/id_rsa
ssh-add ~/.ssh/id_rsa

worked fine for me

After being stuck with that issue for quite a while I just figured out that you have to use the username git (I used a deploykey in a GitHub repo, unsure if that matters) and then it worked for me:

auth, err := ssh.NewPublicKeysFromFile("git", cfg.PrivateKeyFilePath, cfg.Passphrase)