首页 > 解决方案 > 如何让 VSCode 远程容器读取 ssh 配置文件?

问题描述

我有一个相当广泛的.ssh/config文件,其中包含以下条目:

Host gitlab.com
    Preferredauthentications publickey
    HostName gitlab.com
    User git
    IdentityFile ~/.ssh/gitlab.pub
    IdentitiesOnly yes

我还使用 SSH 代理来提供私钥。现在,当我在 VSCode 中使用此设置时,容器似乎不知道配置文件。我遇到如下错误:

Received disconnect from 172.65.251.78 port 22:2: Too many authentication failures
Disconnected from 172.65.251.78 port 22
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.

通过GIT_SSH_COMMAND="ssh -v" git fetch在容器中运行,我发现所有密钥都已尝试过,并且在 5 次尝试后 Gitlab SSH 服务器不想继续。所以 ssh-agent 被转发到容器,而不是配置文件。在容器外,一切正常。

有人对此有解决方案吗?

我的环境:

Version: 1.53.0
Commit: 8490d3dde47c57ba65ec40dd192d014fd2113496
Date: 2021-02-03T15:56:04.185Z
Electron: 11.2.1
Chrome: 87.0.4280.141
Node.js: 12.18.3
V8: 8.7.220.31-electron.0
OS: Linux x64 5.10.13-arch1-2

Remote-Containers: v0.158.0

标签: gitvisual-studio-codesshvscode-devcontainer

解决方案


 IdentityFile ~/.ssh/gitlab.pub

这似乎是错误的:通常,IdentityFile 引用私有SSH 密钥,而不是公共密钥:

IdentityFile ~/.ssh/gitlab

推荐阅读