关于Go Module拉取私有仓库时,遇到terminal prompts disabled权限的问题。go get 包代理设置

访问github 私有仓库设置

前提 ssh秘钥已配好

现象

fatal: could not read Username for 'https://github.com': terminal prompts disabled
Confirm the import path was entered correctly.

[root@vm10-10-128-68 mywarning]# go get github.com/zhangmingda3/ksyunwarning@0795e78e88bf71a84968d3b5a491f79e3727a6eb
go: github.com/zhangmingda3/ksyunwarning@0795e78e88bf71a84968d3b5a491f79e3727a6eb: invalid version: git ls-remote -q origin in /root/go/pkg/mod/cache/vcs/3b597a61692748d78723c42315f9aace7226099be1a17d10da0a21a735d16ad0: exit status 128:
    fatal: could not read Username for 'https://github.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.
[root@vm10-10-128-68 mywarning]#

设置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/"

配置后查看git config

[root@vm10-10-128-68 mywarning]# git config --list
user.name=zhangmingda3
user.email=zhangmingda666888@163.com
url.git@github.com:.insteadof=https://github.com/

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

设置 GOPRIVATE

通过GOPRIVATE来指定你的仓库

go env -w GOPRIVATE=xxx.com/xxx

再次 go get 

 

goLand 访问github.com 下载包超时 

connectex: A connection attempt failed because the connected party did not properly respond af
ter a period of time, or established connection failed because connected host has failed to respond.

 

 配置代理 

go env -w GOPROXY=https://goproxy.cn,direct 

再次下载成功

 

posted on   zhangmingda  阅读(4824)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示