How to `go get` private repos using SSH key auth with password

Viewed 983

I usually set a passphrase in my ssh keys so that, in case of it gets compromised, I might get some time to rotate to a new one.

However, when working with go modules, I noticed that when executing a go get and making use of keys with passphrase, I get the error below

git@github.com: Permission denied (publickey).

Is there any way to be prompted for this password when resolving dependencies in Go?

For now, I removed the password :(

2 Answers

use an agent. On Linux or Macos the process is

   ssh-agent bash

this first step starts a shell with ssh-agent

   ssh-add ~/.ssh/id_rsa

the second step adds a key to the agent, ~/.ssh/id_rsa is the path to the key. After this step it will ask once for the passphrase

Once you've done these things any command in the new shell will use the keys loaded with ssh-add

You may also try to change the way go get invokes ssh, by disabling batch mode:

env GIT_SSH_COMMAND="ssh -o ControlMaster=no -o BatchMode=no" go get github.com/<YOUR_REPO_HERE>
Related