Golang 使用Github 私有库

1.生成SSH Key

ssh-keygen -t ed25519 -C "your_email@example.com"

C:\Users\<用户名>\.ssh\id_ed25519

C:\Users\<用户名>\.ssh\id_ed25519.pub 公钥

2. 公钥上传到 Github

复制id_ed25519.pub,粘贴到Github => SSH Keys => Key

Golang 使用Github 私有库

添加公钥到 known_hosts文件

ssh-add ~/.ssh/id_ed25519

添加后可以使用 ssh -T git@github.com 来测试是否成功

成功提示

Hi username ! You’ve successfully authenticated, but GitHub does not provide shell access.

3. 设置Git

git config --global url."git@github.com:".insteadOf "https://github.com/"

4. Golang 设置 GOPRIVATE 环境变量

go env -w GOPRIVATE="github.com/username/projectname"

5. 在现有项目中使用 私有库

go get github.com/username/projectname

常见错误

fatal: could not read Username for ‘https://github.com’: terminal prompts disabled

终端禁用了弹出框,无法输入密码,可以尝试下面方法:

  1. git config –global –add credential.helper manager
  2. 添加环境变量 GIT_TERMINAL_PROMPT=1

推荐使用SSH KEYS

版权声明:本文为NII.CN的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://nii.cn/4203.html 发布者:nii

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
nii的头像nii
上一篇 2023-05-26 11:38
下一篇 2023-10-11 10:39

相关推荐

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

联系我们

邮件:83390286[AT]QQ.COM

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信