如何使用SSH密钥身份验证密码来获取私有存储库

huangapple go评论79阅读模式
英文:

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

问题

我通常会在我的ssh密钥中设置一个密码短语,这样,如果密钥被泄露,我可以有一些时间来更换新的密钥。

然而,当我在使用go模块时,我注意到当执行go get并使用带有密码短语的密钥时,会出现以下错误:

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

在Go中解析依赖项时,有没有办法提示输入密码?

目前,我已经移除了密码。

英文:

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 如何使用SSH密钥身份验证密码来获取私有存储库

答案1

得分: 11

使用代理。在Linux或MacOS上,该过程是:

ssh-agent bash

这一步首先启动一个带有ssh-agent的shell。

ssh-add ~/.ssh/id_rsa

第二步将一个密钥添加到代理中,~/.ssh/id_rsa是密钥的路径。在这一步之后,它会要求输入一次密码短语。

完成这些步骤后,新shell中的任何命令都将使用通过ssh-add加载的密钥。

英文:

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

答案2

得分: 0

你也可以尝试更改go get调用ssh的方式,通过禁用批处理模式:

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

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

env GIT_SSH_COMMAND=&quot;ssh -o ControlMaster=no -o BatchMode=no&quot; go get github.com/&lt;YOUR_REPO_HERE&gt;

huangapple
  • 本文由 发表于 2021年10月23日 03:11:47
  • 转载请务必保留本文链接:https://go.coder-hub.com/69682030.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定