Go Module 私有仓库:fatal: could not read Username for ‘https://xxx.com‘: terminal prompts disabled

说明

关于Go Module拉取私有仓库时,遇到terminal prompts disabled权限的问题。

错误信息
go get: gitee.com/xxxxx/proto@v1.0.0: reading https://goproxy.cn/gitee.com/xxxxxr/proto/@v/v1.0.1.info: 404 Not Found
        server response:
        not found: gitee.com/xxxx/proto@v1.0.1: invalid version: git ls-remote -q origin in /tmp/gopath/pkg/mod/cache/vcs/38e9fe3a96fe68d3df32046929625c624d2613d5084f9e174c10834d6791c202: exit status 128:
                fatal: could not read Username for 'https://gitee.com': terminal prompts disabled
        Confirm the import path was entered correctly.
        If this is a private repository, see https://golang.org/doc/faq#git_https for additional information.
设置GIT_TERMINAL_PROMPT

go get源码包中有以下一段代码:

90	 // Disable any prompting for passwords by Git.
91	 // Only has an effect for 2.3.0 or later, but avoiding
92	 // the prompt in earlier versions is just too hard.
93	 // If user has explicitly set GIT_TERMINAL_PROMPT=1, keep
94	 // prompting.
95	 // See golang.org/issue/9341 and golang.org/issue/12706.
96	 if os.Getenv("GIT_TERMINAL_PROMPT") == "" {
97	 	 os.Setenv("GIT_TERMINAL_PROMPT", "0")
98	 }

可以通过设置环境变量GIT_TERMINAL_PROMPT = 1 来开启账号密码的验证。

https替换成ssh

需要在仓库绑定SSH公钥

git config --global url."git@xxx.com:".insteadOf "https://xxx.com/"

配置仓库的全局选项将https替代成ssh

设置 GOPRIVATE

通过GOPRIVATE来指定你的仓库

go env -w GOPRIVATE=xxx.com/xxx
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 4
    评论
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值