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

3

8

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

[email protected]: Permission denied (publickey).

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

For now, I removed the password :(

Unwitting answered 22/10, 2021 at 19:11 Comment(2)
Normally you would use an ssh agent, is that not an option?Shot
@Shot fantastic. Worked like a charm. Definitely is an optionUnwitting
I
16

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

Iodometry answered 22/10, 2021 at 20:15 Comment(0)
R
0

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>
Resemble answered 7/1, 2022 at 9:20 Comment(0)
S
0

Under Windows, following the answer Git with SSH on Windows related to Windows OpenSSH, you should also check that Git uses the correct ssh client to perform operations under "go get" command:

In a classic commandline window:

echo %GIT_SSH%

If the environment variable is not set, locate the ssh client:

where ssh

and set the variable to the output value (for ex., C:\Windows\System32\OpenSSH\ssh.exe):

setx GIT_SSH C:\Windows\System32\OpenSSH\ssh.exe

SETX will preserve the variable thru sessions.

Siva answered 27/6 at 7:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.