当前位置:首页 > 文章列表 > Golang > Go问答 > GitHub / 私人存储库 / SSH:go get/go mod tidy 失败,而 git clone 正在工作

GitHub / 私人存储库 / SSH:go get/go mod tidy 失败,而 git clone 正在工作

来源:stackoverflow 2024-04-04 20:36:42 0浏览 收藏

有志者,事竟成!如果你在学习Golang,那么本文《GitHub / 私人存储库 / SSH:go get/go mod tidy 失败,而 git clone 正在工作》,就很适合你!文章讲解的知识点主要包括,若是你对本文感兴趣,或者是想搞懂其中某个知识点,就请你继续往下看吧~

问题内容

我希望找到过去几天困扰我的问题的答案 - 我已经阅读了很多线程、帮助程序和出版物,但似乎没有找到解决方案。 我对 ssh 有点陌生。

问题如下: 使用 go getgo mod tidy 命令时,我无法获取/安装/刷新属于我的项目的模块, 虽然在任何终端中通过 ssh 或通过 tortoisegit 运行同一存储库的 git clone 都工作正常, 即我可以克隆,但无法构建。

获取模块失败的方式如下(个人数据混淆):

example.com/hello/projects/src/git.<orgname>.com/<reponame>/<subreponame>/tests/functional/resources tested by
    example.com/hello/projects/src/git.<orgname>.com/<reponame>/<subreponame>/tests/functional/resources.test imports
    git.<orgname>.com/<reponame>/<subreponame>/tests/functional/resources/vm_specific: module git.<orgname>.com/<reponame>/<subreponame>/tests/functional/resources/vm_specific: git ls-remote -q origin in c:\go\projects\pkg\mod\cache\vcs\a5d519aeafc0ac08e2b20d7c8a6a8b2cea11cda88cb058cf2ebcc079d07b260a: exit status 128:
    debug3: expanded userknownhostsfile '~/.ssh/known_hosts' -> 'c:\\users\\<username>/.ssh/known_hosts'
    debug3: expanded userknownhostsfile '~/.ssh/known_hosts2' -> 'c:\\users\\<username>/.ssh/known_hosts2'
    debug2: resolving "git.<orgname>.com" port <port>
    debug3: resolve_host: lookup git.<orgname>.com:<port>
    debug3: ssh_connect_direct: entering
    debug1: connecting to git.<orgname>.com [10.xxx.x.xx] port <port>.
    debug1: connection established.
    ...
    debug1: local version string ssh-2.0-openssh_for_windows_8.9
    debug1: remote protocol version 2.0, remote software version apache-sshd-2.4.0
    debug1: compat_banner: no match: apache-sshd-2.4.0
    debug2: fd 3 setting o_nonblock
    debug1: authenticating to git.<orgname>.com:<port> as 'git'
    ...
    debug1: authentications that can continue: publickey
    ...
    debug3: send packet: type 50
    debug3: receive packet: type 52
    authenticated to git.<orgname>.com ([10.xxx.x.xx]:<port>) using "publickey".
    ...
    debug1: sending command: git-upload-pack '/scm/<reponame>/<subreponame>.git'
    debug2: channel 0: request exec confirm 1
    debug3: send packet: type 98
    debug2: channel_input_open_confirmation: channel 0: callback done
    debug2: channel 0: open confirm rwindow 2097152 rmax 32768
    debug3: receive packet: type 99
    debug2: channel_input_status_confirm: type 99 id 0
    debug2: exec request accepted on channel 0
    debug2: channel 0: rcvd ext data 106
    debug3: receive packet: type 96
    debug2: channel 0: rcvd eof
    debug2: channel 0: output open -> drain
    debug3: receive packet: type 98
    debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
    debug3: receive packet: type 97
    debug2: channel 0: rcvd close
    debug2: chan_shutdown_read: channel 0: (i0 o1 sock -1 wfd 4 efd 6 [write])
    debug2: channel 0: input open -> closed
    debug3: channel 0: will not send data after close
    debug2: channel 0: obuf_empty delayed efd 6/(106)
    debug2: channel 0: written 106 to efd 6
    repository not found
    the requested repository does not exist, or you do not have permission to access it.
    debug3: channel 0: will not send data after close
    debug2: channel 0: obuf empty
    debug2: chan_shutdown_write: channel 0: (i3 o1 sock -1 wfd 5 efd 6 [write])
    debug2: channel 0: output drain -> closed
    fatal: could not read from remote repository.

    please make sure you have the correct access rights
    and the repository exists.
    debug2: channel 0: almost dead
    debug2: channel 0: gc: notify user
    debug2: channel 0: gc: user detached
    debug2: channel 0: send close
    debug3: send packet: type 97
    debug2: channel 0: is dead
    debug2: channel 0: garbage collecting
    debug1: channel 0: free: client-session, nchannels 1
    debug3: channel 0: status: the following connections are open:
      #0 client-session (t4 r0 i3/0 o3/0 e[write]/0 fd -1/-1/6 sock -1 cc -1 io 0x00/0x08)

    debug3: send packet: type 1
    transferred: sent 3268, received 2200 bytes, in 0.2 seconds
    bytes per second: sent 15169.6, received 10212.1
    debug1: exit status 1

如果需要更完整的日志,我可以将其上传到某个地方。

ssh -t(vvv 设置为默认值)的最后几行 git@git..com

debug3: send packet: type 50
    debug3: receive packet: type 52
    debug1: authentication succeeded (publickey).
    authenticated to git.<orgname>.com ([10.xxx.x.xx]:<port>).
    debug1: channel 0: new [client-session]
    debug3: ssh_session2_open: channel_new: 0
    debug2: channel 0: send open
    debug3: send packet: type 90
    debug1: entering interactive session.
    debug1: pledge: filesystem full
    debug3: receive packet: type 91
    debug2: channel_input_open_confirmation: channel 0: callback start
    debug2: fd 3 setting tcp_nodelay
    debug3: set_sock_tos: set socket 3 ip_tos 0x08
    debug2: client_session2_setup: id 0
    debug2: channel 0: request shell confirm 1
    debug3: send packet: type 98
    debug2: channel_input_open_confirmation: channel 0: callback done
    debug2: channel 0: open confirm rwindow 2097152 rmax 32768
    debug3: receive packet: type 100
    debug2: channel_input_status_confirm: type 100 id 0
    shell request failed on channel 0

我使用的公钥源自 openssh 的 ssh-keygen 生成的密钥 - 它是新生成的并添加到我的 git 配置文件中。 git clone 因此工作正常,这已经让我发疯了。 我已经有大部分模块无法在远程私有仓库中检查,这更疯狂。

我不喜欢这部分,这很可能意味着我的证书有问题 -

使用 git..com ([10.xxx.x.xx]:) 进行身份验证 “公钥”。

这部分,因为 aix 上的 openssh 在启用 efs 时默认请求 pkcs12 支持,非 aix 系统可能会拒绝这些 pkcs12 请求。

debug2:通道 0:obuf_empty 延迟 efd 6/(106) debug2:通道0:将106写入efd 6

请参阅下面我的配置中的更改。

我的环境:

  • win10 企业版
  • git 版本 - 2.31.1.windows.1
  • 我通常通过 tortoisegit 2.13.0.1 克隆
  • 在 cmd/powershell 中使用 ssh 客户端 - openssh_for_windows_8.9,手动安装

go env:(个人数据已混淆)

set go111module=
    set goarch=amd64
    set gobin=
    set gocache=c:\users\<username>\appdata\local\go-build
    set goenv=c:\users\<username>\appdata\roaming\go\env
    set goexe=.exe
    set goexperiment=
    set goflags=
    set gohostarch=amd64
    set gohostos=windows
    set goinsecure=
    set gomodcache=c:\program files\go\pkg\mod
    set gonoproxy=*.<orgname>.com;git.<orgname>.com/users/<username>
    set gonosumdb=*.<orgname>.com;git.<orgname>.com/users/<username>
    set goos=windows
    set gopath=c:\program files\go
    set goprivate=*.<orgname>.com;git.<orgname>.com/users/<username>
    set goproxy=https://proxy.golang.org,direct
    set goroot=c:\program files\go
    set gosumdb=sum.golang.org
    set gotmpdir=
    set gotooldir=c:\program files\go\pkg\tool\windows_amd64
    set govcs=
    set goversion=go1.18.3
    set gccgo=gccgo
    set goamd64=v1
    set ar=ar
    set cc=gcc
    set cxx=g++
    set cgo_enabled=1
    set gomod=nul
    set gowork=
    set cgo_cflags=-g -o2
    set cgo_cppflags=
    set cgo_cxxflags=-g -o2
    set cgo_fflags=-g -o2
    set cgo_ldflags=-g -o2
    set pkg_config=pkg-config
    set gogccflags=-m64 -mthreads -fmessage-length=0 -fdebug-prefix-map=c:\users\user~1.nam\appdata\local\temp\go-build1143995380=/tmp/go-build -gno-record-gcc-switches

我的 ssh 配置:

# github for src
        host git.<orgname>.com
           serveraliveinterval 600
           tcpkeepalive yes
           ipqos throughput
           addkeystoagent yes
           hostname git.<orgname>.com
           port <port>
           user <username>
           preferredauthentications publickey
           identityfile c:\users\<username>\.ssh\git_rsa
           #identityfile ~/.ssh/git_rsa
           pubkeyacceptedkeytypes +ssh-rsa
           #forwardagent no
           #allowpkcs12keystoreautoopen no
           loglevel debug3
  • 该证书之前已添加到代理中,但为了确定起见,我在这里指定了它,并且根据日志似乎采用了正确的证书进行身份验证。

  • 它没有密码。

  • 我的 known-hosts 中没有完全未知的条目,并且正在使用根据证书时间戳判断的正确条目。

  • 我发现可以通过将 allowpkcs12keystoreautoopen 设置为 no 来禁用 pkcs12 请求,但它被标记为错误选项 -

    c:\go\projects\src\git.<orgname>.com\<reponame>\<subreponame>>go get git.<orgname>.com/<name>/go-service/log
     go: module git.<orgname>.com/<name>/go-service/log: git ls-remote -q origin in c:\go\projects\pkg\mod\cache\vcs\d0d607237eeba0d1c9d5ce996ed36c0f3746b2c8f94b538ace2d3f2a9476839e: exit status 128:
         c:\\users\\<username>/.ssh/config: line 15: bad configuration option: allowpkcs12keystoreautoopen
         c:\\users\\<username>/.ssh/config: terminating, 1 bad configuration options

git 配置:

  • 全球:

    [user]
         name = <username>
         email = <usrname>@<orgname>.com
    
     [url "ssh://git@git.<orgname>.com:<port>/"]
         insteadof = https://git.<orgname>.com
  • 系统:

    [url "ssh://git@git.<orgname>.com:<port>/"]
         insteadof = https://git.<orgname>.com/

git远程-v:

origin  ssh://git@git.<orgname>.com:<port>/~<username>/<subreponame>.git (fetch)
    origin  ssh://git@git.<orgname>.com:<port>/~<username>/<subreponame>.git (push)
  • 与我用于克隆的相同,

存储库配置:

[remote "origin"]
        url = ssh://git@git.<orgname>.com:<port>/~<username>/<subreponame>.git
        fetch = +refs/heads/*:refs/remotes/origin/*

我尝试了 ssh:// 和 git@git...但没有帮助。

模块配置(自动设置),但是:

[remote "origin"]
        url = https://git.<orgname>.com/scm/<reponame>/<subreponame>.git
        fetch = +refs/heads/*:refs/remotes/origin/*

我现在没有想法。


正确答案


我建议不要将 go get 与私有存储库一起使用。此命令将存储库缓存在 pkg.go.dev 上,从而将它们公开给全世界。我很尴尬地发现我们的私人开发项目在那里公开发布。

我在文件系统中手动部署私有依赖项,并使用替换在 go.mod 中指定依赖项:

require your.server/your/package 1.2.3

replace your.server/your/package 1.2.3 => /path/to/local/your/package

本篇关于《GitHub / 私人存储库 / SSH:go get/go mod tidy 失败,而 git clone 正在工作》的介绍就到此结束啦,但是学无止境,想要了解学习更多关于Golang的相关知识,请关注golang学习网公众号!

版本声明
本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
东风汽车新能源“对赌”激励机制见成效,猛士917销售势头强劲东风汽车新能源“对赌”激励机制见成效,猛士917销售势头强劲
上一篇
东风汽车新能源“对赌”激励机制见成效,猛士917销售势头强劲
Galaxy Z Fold5:突破折叠屏技术 为用户带来绚丽视觉震撼
下一篇
Galaxy Z Fold5:突破折叠屏技术 为用户带来绚丽视觉震撼
查看更多
最新文章
查看更多
课程推荐
  • 前端进阶之JavaScript设计模式
    前端进阶之JavaScript设计模式
    设计模式是开发人员在软件开发过程中面临一般问题时的解决方案,代表了最佳的实践。本课程的主打内容包括JS常见设计模式以及具体应用场景,打造一站式知识长龙服务,适合有JS基础的同学学习。
    542次学习
  • GO语言核心编程课程
    GO语言核心编程课程
    本课程采用真实案例,全面具体可落地,从理论到实践,一步一步将GO核心编程技术、编程思想、底层实现融会贯通,使学习者贴近时代脉搏,做IT互联网时代的弄潮儿。
    508次学习
  • 简单聊聊mysql8与网络通信
    简单聊聊mysql8与网络通信
    如有问题加微信:Le-studyg;在课程中,我们将首先介绍MySQL8的新特性,包括性能优化、安全增强、新数据类型等,帮助学生快速熟悉MySQL8的最新功能。接着,我们将深入解析MySQL的网络通信机制,包括协议、连接管理、数据传输等,让
    497次学习
  • JavaScript正则表达式基础与实战
    JavaScript正则表达式基础与实战
    在任何一门编程语言中,正则表达式,都是一项重要的知识,它提供了高效的字符串匹配与捕获机制,可以极大的简化程序设计。
    487次学习
  • 从零制作响应式网站—Grid布局
    从零制作响应式网站—Grid布局
    本系列教程将展示从零制作一个假想的网络科技公司官网,分为导航,轮播,关于我们,成功案例,服务流程,团队介绍,数据部分,公司动态,底部信息等内容区块。网站整体采用CSSGrid布局,支持响应式,有流畅过渡和展现动画。
    484次学习
查看更多
AI推荐
  • 茅茅虫AIGC检测:精准识别AI生成内容,保障学术诚信
    茅茅虫AIGC检测
    茅茅虫AIGC检测,湖南茅茅虫科技有限公司倾力打造,运用NLP技术精准识别AI生成文本,提供论文、专著等学术文本的AIGC检测服务。支持多种格式,生成可视化报告,保障您的学术诚信和内容质量。
    144次使用
  • 赛林匹克平台:科技赛事聚合,赋能AI、算力、量子计算创新
    赛林匹克平台(Challympics)
    探索赛林匹克平台Challympics,一个聚焦人工智能、算力算法、量子计算等前沿技术的赛事聚合平台。连接产学研用,助力科技创新与产业升级。
    171次使用
  • SEO  笔格AIPPT:AI智能PPT制作,免费生成,高效演示
    笔格AIPPT
    SEO 笔格AIPPT是135编辑器推出的AI智能PPT制作平台,依托DeepSeek大模型,实现智能大纲生成、一键PPT生成、AI文字优化、图像生成等功能。免费试用,提升PPT制作效率,适用于商务演示、教育培训等多种场景。
    160次使用
  • 稿定PPT:在线AI演示设计,高效PPT制作工具
    稿定PPT
    告别PPT制作难题!稿定PPT提供海量模板、AI智能生成、在线协作,助您轻松制作专业演示文稿。职场办公、教育学习、企业服务全覆盖,降本增效,释放创意!
    145次使用
  • Suno苏诺中文版:AI音乐创作平台,人人都是音乐家
    Suno苏诺中文版
    探索Suno苏诺中文版,一款颠覆传统音乐创作的AI平台。无需专业技能,轻松创作个性化音乐。智能词曲生成、风格迁移、海量音效,释放您的音乐灵感!
    174次使用
微信登录更方便
  • 密码登录
  • 注册账号
登录即同意 用户协议隐私政策
返回登录
  • 重置密码