我正在尝试使用 ssh 从私有且自托管的 gitlab 存储库导入 go 项目。当我尝试这样做时,出现以下错误。
输出
kbacon@kbacons-macbook-pro bbz % go get -x gitlab.wtf.notworking/bbq/tools@latest # get https://gitlab.wtf.notworking/bbq/tools?go-get=1 # get https://gitlab.wtf.notworking/bbq/tools?go-get=1: 200 ok (0.413s) mkdir -p /users/kbacon/go/pkg/mod/cache/vcs # git3 https://gitlab.wtf.notworking/bbq/tools.git # lock /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179.lock# /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179 for git3 https://gitlab.wtf.notworking/bbq/tools.git cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l 0.013s # cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin 0.020s # cd /users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin # get https://gitlab.wtf.notworking/bbq/tools.git # get https://gitlab.wtf.notworking/bbq/tools.git: 200 ok (0.186s) go: gitlab.wtf.notworking/bbq/[email protected]: reading gitlab.wtf.notworking/bbq/tools/go.mod at revision v1.0.0: unknown revision v1.0.0
.gitconfig
[user] name = kbacon email = [email protected] [url "[email protected]/"] insteadof = https://gitlab.wtf.notworking/
去mod文件
module bbz go 1.14 require ( gitlab.wtf.notworking/bbq/tools v1.0.0 )
gitlab 仓库
gitlab 仓库有一个带有发布标签 v1.0.0
的项目
我用来克隆的地址
ssh://[email protected]:2224/bbq/tools.git
ssh 配置文件
host gitlab.wtf.notworking user [email protected] hostname gitlab.wtf.notworking identityfile ~/.ssh/company_gitlab # path to private key addkeystoagent yes
使用这个 .gitconfig: .gitconfig
[user] name = kbacon email = [email protected] [url "[email protected]:2224/"] insteadof = https://gitlab.wtf.notworking/
然后 go get
命令会请求我的密码,但它应该使用 ssh。为什么它要求我输入密码?
kbacon@kbacons-MacBook-Pro bbz % go get -x gitlab.wtf.notworking/bbq/tools@latest # get https://gitlab.wtf.notworking/bbq/tools?go-get=1 # get https://gitlab.wtf.notworking/bbq/tools?go-get=1: 200 OK (0.424s) mkdir -p /Users/kbacon/go/pkg/mod/cache/vcs # git3 https://gitlab.wtf.notworking/bbq/tools.git # lock /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179.lock# /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179 for git3 https://gitlab.wtf.notworking/bbq/tools.git cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l 0.030s # cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git tag -l cd /Users/kbacon/go/pkg/mod/cache/vcs/3bd57e1dd1ed847c1ac192f16c5f67541135ce037a175de23ec5fb5051d10179; git ls-remote -q origin [email protected]'s password:
如果您使用 ssh url 为 /
而不是 :
,您的 .gitconfig
应该是:
[url "ssh://[email protected]:2224/"] insteadof = https://gitlab.wtf.notworking/
用“:”
[url "[email protected]:2224:"] insteadof = https://gitlab.wtf.notworking/
在您的 ssh 配置文件中,确保使用服务帐户 git
,而不是您的登录名、端口和自定义主机条目:
host gitlab-wtf user git hostname gitlab.wtf.notworking identityfile ~/.ssh/company_gitlab # path to private key addkeystoagent yes port 2224
这样,您就可以使用:
[url "ssh://gitlab-wtf/"] insteadof = https://gitlab.wtf.notworking/
不再有 git@
或 :2224
。