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

PowerShell Invoke-Command SSH PEM密钥连接报错:subsystem request failed on channel 0

解决Invoke-Command SSH连接Linux报错subsystem request failed on channel 0的方案
  • 核心原因:Invoke-Command通过SSH连接时,默认依赖远程的PowerShell子系统,若Linux未安装PowerShell或相关配置缺失,就会触发该报错。以下是具体解决步骤:

1. 检查并安装远程Linux的PowerShell

在远程Linux终端执行:

pwsh --version

返回版本信息则说明已安装;若未安装,根据系统包管理器安装:

  • Debian/Ubuntu:apt update && apt install powershell
  • CentOS/RHEL:dnf install powershell

安装完成后,需在/etc/ssh/sshd_config中添加PowerShell子系统配置:

echo 'Subsystem powershell /usr/bin/pwsh -sshs -NoLogo' >> /etc/ssh/sshd_config

然后重启sshd服务:

systemctl restart sshd

此时再执行命令(注意ScriptBlock需用PowerShell语法,比如Get-ChildItem代替Linux的ls):

Invoke-Command -HostName 'root@192.168.0.2' -KeyFilePath key.pem -ScriptBlock { Get-ChildItem }

2. 改用原生SSH命令执行(无需安装PowerShell)

如果不想在Linux上装PowerShell,直接用PowerShell环境中的原生SSH命令,和手动登录逻辑完全一致:

ssh -i key.pem root@192.168.0.2 "ls"

3. 强制指定SSH传输参数(仅当远程已装PowerShell时生效)

若坚持使用Invoke-Command,可显式指定-SSHTransport参数确保走SSH协议:

Invoke-Command -HostName 'root@192.168.0.2' -KeyFilePath key.pem -SSHTransport -ScriptBlock { Get-ChildItem }

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.11 09:02:10