关于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 2023-02-28 18:55 zhangmingda 阅读(4824) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!
· AI技术革命,工作效率10个最佳AI工具