You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

VS Code通过Remote - SSH连接GitLab报错,PowerShell可正常连接

问题:VS Code Remote-SSH 连接 GitLab 报错「Disallowed command」

环境与配置

我的 OpenSSH 配置文件(C:\Users\testuser\.ssh\config)内容如下:

Host gitlab-test.bpmsoft.ru
Hostname gitlab-test.bpmsoft.ru
User git
IdentityFile C:\Users\testuser\.ssh\id_ed25519
Port 22

已将对应的公钥添加至 GitLab 个人资料中。

问题现象

尝试使用 VS Code 的「Remote - SSH」扩展连接时,选择 Linux 平台后出现错误,相关日志如下:

[18:08:26.567] Using SSH config file "C:\Users\testuser\.ssh\config"
[18:08:26.567] Running script with connection command: "C:\windows\System32\OpenSSH\ssh.exe" -T -D 7224 -F "C:\Users\testuser\.ssh\config" "gitlab-test.bpmsoft.ru" sh
[18:08:26.568] Generated SSH command: 'type "C:\Users\testuser\AppData\Local\Temp\vscode-linux-multi-line-command-gitlab-test.bpmsoft.ru-524993282.sh" | "C:\windows\System32\OpenSSH\ssh.exe" -T -D 7224 -F "C:\Users\testuser\.ssh\config" "gitlab-test.bpmsoft.ru" sh'
[18:08:26.568] Generated SSH command: 'type "C:\Users\testuser\AppData\Local\Temp\vscode-linux-multi-line-command-gitlab-test.bpmsoft.ru-524993282.sh" | "C:\windows\System32\OpenSSH\ssh.exe" -T -D 7224 -F "C:\Users\testuser\.ssh\config" "gitlab-test.bpmsoft.ru" sh'
[18:08:26.569] Using connect timeout of 17 seconds
[18:08:26.569] Terminal shell path: C:\windows\System32\cmd.exe
[18:08:26.818] > 
[18:08:26.818] Got some output, clearing connection timeout
[18:08:27.360] > Disallowed command
[18:08:28.641] "install" terminal command done
[18:08:28.641] Install terminal quit with output: Disallowed command
[18:08:28.641] Received install output: Disallowed command
[18:08:28.642] WARN: $PLATFORM is undefined in installation script output.  Errors may be dropped.
[18:08:28.642] Failed to parse remote port from server output
[18:08:28.645] Resolver error: Error: 
at y.Create (c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:744751)
at t.handleInstallOutput (c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:742832)
at t.tryInstall (c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:865534)
at async c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:824246
at async t.withShowDetailsEvent (c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:827501)
at async A (c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:820760)
at async t.resolve (c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:824898)
at async c:\Users\testuser\.vscode\extensions\ms-vscode-remote.remote-ssh-0.120.0\out\extension.js:2:1113660
[18:08:28.654] ------
[18:08:28.654] No hints found in the recent session.

但通过 PowerShell 可以正常连接 GitLab:

PS C:\Users\testuser> ssh -T gitlab-test.bpmsoft.ru
Welcome to GitLab, @testuser!

原因分析

GitLab 的 SSH 服务是仅支持 Git 操作的受限 Shell,不允许执行任意 Shell 命令(比如 sh)。而 VS Code Remote-SSH 扩展在连接时,会尝试在远程主机上执行 Shell 脚本以安装、初始化远程服务,这类操作超出了 GitLab SSH 服务的权限范围,因此被拒绝。

解决办法

Remote-SSH 扩展的设计目标是连接到可执行完整 Shell 命令的 Linux 服务器,而非 GitLab 这类仅提供 Git 操作的 SSH 端点。如果需要在 VS Code 中操作 GitLab 上的代码,推荐两种方式:

  • 直接在本地克隆 GitLab 仓库,用 VS Code 打开本地目录进行开发
  • 使用 VS Code 的「GitLab Workflow」扩展,直接集成 GitLab 功能(如查看合并请求、流水线状态等),无需通过 SSH 连接 GitLab 服务器

内容的提问来源于stack exchange,提问作者Ivan

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.12 21:34:58