【问题标题】:Go + VsCode: Git -> Permission denied (publickey)Go + VsCode:Git -> 权限被拒绝(公钥)
【发布时间】:2026-02-24 17:10:01
【问题描述】:

我的 VSCode 在使用 Golang 及其在 GitHub 上的更新时遇到了困难。在控制台上,我可以正常使用Git,我还使用go 命令来构建和运行我的go 应用程序,一切正常。但是,当我使用VSCode 时,它根本无法像控制台一样通过SSH 进行身份验证。

完整的信息是:

Error loading workspace: err: exit status 1: stderr: go: github.com/abc/abc@v0.0.0-20210610172953-593247e413d4: 
invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in    
D:\Program Files\Go\bin\pkg\mod\cache\vcs\1c3dbe9a49296bf60aa851731c66574793ff0c41b2a50ff727de076b8a8fce2d: exit status 128: 
Permission denied (publickey). fatal: Could not read from remote repository. 
Please make sure you have the correct access rights and the repository exists. : packages.Load error

有人知道怎么解决吗?

【问题讨论】:

标签: git go visual-studio-code


【解决方案1】:

如果您发现两者之间有任何区别,请检查 VSCode 终端控制台 (CMD):

  • ssh -Tv git@github.com(同样来自 VSCode 中的 CMD)
  • ssh -Tv git@github.com 来自您的常规 CMD

考虑到连接的私钥的路径应该有所不同,这应该会告诉您为什么它在 VSCode 中不起作用(而它在您的 CMD 中起作用)

正如this answer 的 OP 所指出的,一个可能的区别是,在 VSCode 父进程环境中存在 an ssh-agent

如果私钥受密码保护,VSCode 将需要 ssh-agent 来读取所述密钥。

【讨论】:

  • 感谢您的回复。但是,在这两种情况下(在 VSCode 中的 CMD 和我的常规 CMD 中)我都会收到相同的答案 You've successfully authenticated, but GitHub does not provide shell access.。两者的路径也是相同的。还有其他想法吗?
  • @JoeAlmore 也许*.com/a/67580058/6309