【问题标题】:vscode not connecting to multiple gitlab accounts using their respective ssh keysvscode 未使用各自的 ssh 密钥连接到多个 gitlab 帐户
【发布时间】:2022-01-21 14:45:03
【问题描述】:

所以对于 Windows,我看到默认的 ssh 客户端配置应该放在 C:\Users\Admin\.ssh\config 并且我使用相同的,我也是管理员用户。

我添加了以下 ssh 客户端配置:

PS C:\Users\Admin> type .\.ssh\config
Host gc
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/company_gitlab
Host gp
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab_personal

我从 Powershell 对其进行了测试,我的公司和个人 GitLab 帐户使用各自的 ssh 密钥为working

PS C:\Users\Admin> ssh -T git@gc
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
Welcome to GitLab, @johnwilson!

PS C:\Users\Admin> ssh -T git@gp
Enter passphrase for key 'C:\Users\Admin/.ssh/gitlab_personal':
Welcome to GitLab, @jwilson!

但是对于 vscode,当我尝试将更改推送或拉取到远程存储库时,公司和个人 GitLab 帐户都会出现以下错误。

> git push -u gc master
git@gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.

> git push -u gp master
git@gitlab.com: Permission denied (publickey,keyboard-interactive).
fatal: Could not read from remote repository.

我也尝试了here 的建议

PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote add origin git@gc:company/infra_code/userlist.git
PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git remote -v
origin  git@gc:company/infra_code/userlist.git (fetch)
origin  git@gc:company/infra_code/userlist.git (push)

PS C:\Users\Admin\ownCloud\Company\GitLab\userlist> git ls-remote origin
Enter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':
611b36ef47056773c288499cb6974d8671196d78        HEAD
611b36ef47056773c288499cb6974d8671196d78        refs/heads/master

我很困惑,所以 vscode 没有在 windows 上选择默认的 ssh 客户端配置C:\Users\Admin\.ssh\config?。

还是我错过了什么?

【问题讨论】:

标签: visual-studio-code gitlab vscode-remote


【解决方案1】:

检查与名为“gc”的远程关联的远程 URL

cd C:\path\to\gc\repo
git remote -v

如果 URL 以 git@gitlab.com:... 开头,则不会使用 ~/.ssh/config 文件及其 gc 条目。

用正确的 URL 更改它

git remote set-url gc gc:<me>/<myrepo>

然后 VSCode 会选择正确的条目,假设是以用户 Admin 的身份运行。


OP JohnW 确认在the discussion

我添加了一个不带密码的 SSH 密钥,它适用于 vscode。所以这是 VSCode 的 bug 无法使用密码连接 ssh 密钥?

您需要确保首先激活 ssh-agent。
见“Auto-launching ssh-agent on Git for Windows

一旦 SSH 代理启动(并且您的 SSH 私钥密码缓存在其中),您就可以启动 VSCode。那么它应该可以工作了。

【讨论】:

  • 是的,我看到已经完成了,仍然无法用于 vscode。
  • @JohnW 你的意思是远程URL实际上是gc:&lt;me&gt;/&lt;myrepo&gt;,并且被命名为gc?
  • 是的。 PS C:\Users\Admin\ownCloud\Company\GitLab\userlist&gt; git remote -v 输出:gc gc:company/infra_code/userlist.git (fetch)gc gc:company/infra_code/userlist.git (push)
  • @JohnW 在命令 li,e 中,作为用户 admi,git ls-remote gc 可以工作吗? (它应该只返回远程分支的列表,而不获取任何东西:一个很好的轻量级测试)
  • 是的,CLI 始终有效,只有 vscode 有问题。 PS C:\Users\Admin\ownCloud\Company\GitLab\userlist&gt; git ls-remote gcEnter passphrase for key 'C:\Users\Admin/.ssh/company_gitlab':611b36ef47056773c288499cb6974d8671196d78 HEAD611b36ef47056773c288499cb6974d8671196d78 refs/heads/master
猜你喜欢
  • 2015-06-28
  • 2021-01-15
  • 2017-07-02
  • 1970-01-01
  • 2016-10-20
  • 2016-11-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多