go导入包错误 Cloning into ‘xxx‘... fatal: could not read Username

问题:
go get xxx.com/xxx/xxx

cd .; git clone https://xxx.com/xxx/xxx.git

Cloning into ‘xxx’…
fatal: could not read Username for 'https://xxx.com: terminal prompts disabled
package xxx: exit status 128

go get 报错 terminal prompts disabled

原因:
没有获取该包的权限,git没有配置ssh

解决方案:

  1. 方案一
    临时解法:手动输入用户名密码

env GIT_TERMINAL_PROMPT=1 go get xxx.com/xxx/xxx

以GITHUB为例

  1. 方案二
    长期解法:使用已经配置好的git密钥

git config --global --add url.“git@github.com:”.insteadOf “https://github.com/”

  1. 方案三【我自己采用的方法】
    为github配置ssh
    终端输入:
    ssh-keygen -t rsa -C 'xxx@xxx.com' 生成钥匙对
    cat ~/.ssh/id_rsa.pub 将生成的公钥配置到github - 设置 - ssh里面

版权声明:本文为weixin_43856199原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接和本声明。