尝试在我以前的组织中设置go mod tidy
或go mod download
,我要做的就是只是设置GOPRIVATE
,将ssh公钥添加到github/bitbucket/gitlab,将IdentityFile
用于连接自定义域的.ssh/config
设置为.ssh/config
,然后设置.gitconfig
,如下所示:
go env -w GOPRIVATE="github.com/xxx/*"
# .gitconfig
[url "git@github.com:/xxx/"]
insteadOf = https://github.com/xxx/
但是另一个组织不能工作(使用bitbucket),尝试使用auth键或ssh在执行go mod tidy/download
时仍然有问题
go env -w GOPRIVATE="bitbucket.xxx/*,bitbucket.xxx:9022/*"
# 9022 is their ssh port used for cloning a repo
# .gitconfig
#[url "https://:ACCTOKEN@bitbucket.xxx/"] # ACCTOKEN is my access token
[url "ssh://git@bitbucket.xxx:9022/"]
insteadOf = https://bitbucket.xxx/
两者都没有工作,如果没有.gitconfig
,就会显示错误:
go: bitbucket.xxx/yyy/zzz/aaa/bbb@v0.0.0-20220728131025-25f2fba58852: invalid version: git ls-remote -q origin in /home/asd/go/pkg/mod/cache/vcs/be703481c10c8d59451fefcffbf5e7341aab5edf1c25acbaa8356c8fbeef42d2: exit status 128:
fatal: could not read Username for 'https://bitbucket.xxx': 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.
如果在.gitconfig
上使用访问令牌,错误是:
go: bitbucket.xxx/yyy/zzz/aaa/bbb@v0.0.0-20220728131025-25f2fba58852: invalid version: git ls-remote -q origin in /home/asd/go/pkg/mod/cache/vcs/be703481c10c8d59451fefcffbf5e7341aab5edf1c25acbaa8356c8fbeef42d2: exit status 128:
fatal: Authentication failed for 'https://bitbucket.xxx/scm/yyy/zzz.git/'
^无法正确使用此、密码或访问令牌,因此总是被拒绝。
如果在.gitconfig
上使用ssh,错误是:
go: bitbucket.xxx/yyy/zzz/aaa/bbb@v0.0.0-20220728131025-25f2fba58852: invalid version: git ls-remote -q origin in /home/asd/go/pkg/mod/cache/vcs/be703481c10c8d59451fefcffbf5e7341aab5edf1c25acbaa8356c8fbeef42d2: exit status 128:
Repository not found
The requested repository does not exist, or you do not have permission to access it.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.
我可以正常使用这个git clone ssh://git@bitbucket.xxx:9022/yyy/zzz.git
,但如果使用go mod
(或者使用IntelliJ),则失败。
xxx
是组织域名,组织强制对ssh密钥使用密码。
我漏掉了什么吗?或者如何强制go mod
使用ssh而不是https来克隆/下载?
发布于 2022-09-08 07:56:59
不过,.gitconfig
错了,它应该是这样的:
[url "ssh://git@bitbucket.xxx:9022/"]
insteadOf = https://bitbucket.xxx/scm/
在我的例子中,后缀中有scm
。
现在可以正确的git clone https://bitbucket.xxx/scm/yyy/zzz.git
,与go mod
也工作。
https://stackoverflow.com/questions/73645428
复制相似问题