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

VSCode Remote SSH连接Windows服务器失败:PowerShell未识别问题求助

VSCode Remote SSH无法连接Windows服务器问题排查

环境与问题

  • 客户端与服务器均为Windows系统,已安装Windows OpenSSH
  • 终端可正常SSH连接目标服务器pvc-ftt-3,但VSCode Remote SSH无法连接;且VSCode可正常连接其他同类型Windows服务器
  • 此前该服务器可正常通过VSCode Remote SSH连接

已尝试的修复操作

  • 删除SSH配置项、授权密钥、known_hosts文件
  • 删除服务器端.vscode_server目录(未自动重新生成)
  • 重装VSCode Remote SSH扩展、客户端VSCode
  • 重装两端OpenSSH服务及客户端
  • 设置服务器默认提示符为PowerShell

连接报错日志

[09:46:45.214] Log Level: 2
[09:46:45.230] SSH Resolver called for "ssh-remote+pvc-ftt-3", attempt 1
[09:46:45.230] "remote.SSH.useLocalServer": false
[09:46:45.231] "remote.SSH.showLoginTerminal": false
[09:46:45.231] "remote.SSH.remotePlatform": {"129.97.68.241":"linux","192.168.1.231":"linux","pvc-ftt-6":"windows"}
[09:46:45.231] "remote.SSH.path": undefined
[09:46:45.231] "remote.SSH.configFile": undefined
[09:46:45.231] "remote.SSH.useFlock": true
[09:46:45.231] "remote.SSH.lockfilesInTmp": false
[09:46:45.231] "remote.SSH.localServerDownload": auto
[09:46:45.231] "remote.SSH.remoteServerListenOnSocket": false
[09:46:45.231] "remote.SSH.showLoginTerminal": false
[09:46:45.232] "remote.SSH.defaultExtensions": []
[09:46:45.232] "remote.SSH.loglevel": 2
[09:46:45.232] "remote.SSH.enableDynamicForwarding": true
[09:46:45.232] "remote.SSH.enableRemoteCommand": false
[09:46:45.232] "remote.SSH.serverPickPortsFromRange": {}
[09:46:45.232] "remote.SSH.serverInstallPath": {}
[09:46:45.235] VS Code version: 1.81.1
[09:46:45.235] Remote-SSH version: remote-ssh@0.102.0
[09:46:45.235] win32 x64
[09:46:45.238] SSH Resolver called for host: pvc-ftt-3
[09:46:45.238] Setting up SSH remote "pvc-ftt-3"
[09:46:45.242] Using commit id "6c3e3dba23e8fadc360aed75ce363ba185c49794" and quality "stable" for server
[09:46:45.246] Install and start server if needed
[09:46:46.728] Checking ssh with "C:\Program Files\Google\Chrome\Application\ssh.exe -V"
[09:46:46.732] Got error from ssh: spawn C:\Program Files\Google\Chrome\Application\ssh.exe ENOENT
[09:46:46.733] Checking ssh with "C:\WINDOWS\system32\ssh.exe -V"
[09:46:46.735] Got error from ssh: spawn C:\WINDOWS\system32\ssh.exe ENOENT
[09:46:46.736] Checking ssh with "C:\WINDOWS\ssh.exe -V"
[09:46:46.738] Got error from ssh: spawn C:\WINDOWS\ssh.exe ENOENT
[09:46:46.738] Checking ssh with "C:\WINDOWS\System32\Wbem\ssh.exe -V"
[09:46:46.741] Got error from ssh: spawn C:\WINDOWS\System32\Wbem\ssh.exe ENOENT
[09:46:46.742] Checking ssh with "C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe -V"
[09:46:46.745] Got error from ssh: spawn C:\WINDOWS\System32\WindowsPowerShell\v1.0\ssh.exe ENOENT
[09:46:46.745] Checking ssh with "C:\WINDOWS\System32\OpenSSH\ssh.exe -V"
[09:46:46.905] > OpenSSH_for_Windows_8.6p1, LibreSSL 3
[09:46:46.906] > .4.3

[09:46:46.912] Remote command length: 6211/8192 characters
[09:46:46.912] Running script with connection command: "C:\WINDOWS\System32\OpenSSH\ssh.exe" -T -D 59772 "pvc-ftt-3" powershell
[09:46:46.918] Terminal shell path: C:\WINDOWS\System32\cmd.exe
[09:46:47.792] > alab@pvc-ftt-3's password:]0;C:\WINDOWS\System32\cmd.exe
[09:46:47.792] Got some output, clearing connection timeout
[09:46:47.793] Showing password prompt
[09:46:53.517] Got password response
[09:46:53.519] "install" wrote data to terminal: "********************"
[09:46:53.584] > 
[09:46:54.097] > powershell : The term 'powershell' is not recognized as the name of a cmdlet, function, script 
> file, or operable program. Check the spelling of the name, or if a path was included, verify that 
> the path is correct and try again.
> At line:1 char:1
> + powershell
> + ~~~~~~~~~~
>     + CategoryInfo          : ObjectNotFound: (powershell:String) [], CommandNotFoundException
>     + FullyQualifiedErrorId : CommandNotFoundException
>  
[09:46:55.434] "install" terminal command done
[09:46:55.435] Install terminal quit with output:  
[09:46:55.435] Received install output:  
[09:46:55.437] Resolver error: Error: 
    at m.Create (c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:584145)
    at c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:581833
    at t.handleInstallOutput (c:\Users\kchandan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:582627)
    at t.tryInstall (c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:681881)
    at async c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:644110
    at async t.withShowDetailsEvent (c:\Users\kchandan\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:647428)
    at async t.resolve (c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:645160)
    at async c:\Users\me\.vscode\extensions\ms-vscode-remote.remote-ssh-0.102.0\out\extension.js:1:720916
[09:46:55.448] ------

解决方案

1. 手动指定服务器平台为Windows

从日志可见remote.SSH.remotePlatform配置中仅pvc-ftt-6被标记为Windows,pvc-ftt-3未配置,导致VSCode默认按Linux处理:

  • 打开VSCode设置,搜索remote.SSH.remotePlatform
  • 添加配置条目:"pvc-ftt-3": "windows"
  • 保存设置后重启VSCode尝试连接

2. 确保服务器端PowerShell可全局调用

SSH登录服务器后执行以下操作:

  • 运行where powershell,确认返回有效路径(通常为C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe)
  • 若未返回路径,将上述路径添加至服务器系统环境变量PATH中,重启服务器后重试

3. 强制指定连接时的Shell路径

修改SSH配置文件(通常位于~/.ssh/config),为目标服务器添加明确的Shell指定:

Host pvc-ftt-3
    HostName pvc-ftt-3
    User alab
    RemoteCommand C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
    RequestTTY yes

保存配置后重新尝试连接

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.12 01:55:01