Issue
Tried to go mod tidy
or go mod download
on my old organization, all I need to do is just to set GOPRIVATE
, add ssh public key to the github/bitbucket/gitlab, set .ssh/config
to which IdentityFile
to be used to connect for custom domain, then set .gitconfig
something like this:
go env -w GOPRIVATE="github.com/xxx/*"
# .gitconfig
[url "[email protected]:/xxx/"]
insteadOf = https://github.com/xxx/
but this other organization won't work (using bitbucket), tried using auth key or ssh still got problem when doing 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://:[email protected]/"] # ACCTOKEN is my access token
[url "ssh://[email protected]:9022/"]
insteadOf = https://bitbucket.xxx/
both didn't work, without the .gitconfig
it shows error:
go: bitbucket.xxx/yyy/zzz/aaa/[email protected]: 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.
if using access token on .gitconfig
, the error is:
go: bitbucket.xxx/yyy/zzz/aaa/[email protected]: 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/'
^ cannot git clone https://bitbucket.xxx/scm/yyy/zzz.git
properly using this, password or access token always rejected
if using ssh on .gitconfig
, the error is:
go: bitbucket.xxx/yyy/zzz/aaa/[email protected]: 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.
I can git clone ssh://[email protected]:9022/yyy/zzz.git
normally using this .gitconfig
, but failed if using go mod
(or when using IntelliJ).
xxx
is the organization domain name, the organization enforced to use password on ssh key.
Did I missed something? Or how can I force go mod
to clone/download using ssh instead of https?
Solution
Nevermind, the .gitconfig
is wrong, it should be like this:
[url "ssh://[email protected]:9022/"]
insteadOf = https://bitbucket.xxx/scm/
^ in my case, there is scm
in the suffix.
now can git clone https://bitbucket.xxx/scm/yyy/zzz.git
properly, with go mod
also works.
Answered By - Kokizzu Answer Checked By - Candace Johnson (WPSolving Volunteer)