Powershell: 使用 SSH 密钥身份验证时出现新的 PSSession 错误“通道 0 上的子系统请求失败”

创建于 2018-01-19  ·  3评论  ·  资料来源: PowerShell/PowerShell

繁殖步骤

New-PSSession -SSHTransport -UserName SpockAdmin -KeyFilePath /Users/tsulli/Spocks_Private_Key.pem -HostName x.x.x.x

症状

New-PSSession : [xxxx] 后台进程报告错误并显示以下消息:SSH 客户端会话已结束并显示错误消息:子系统请求在通道 0 上失败。

注意:我能够使用 Mac 的ssh命令行客户端成功通过 SSH 进入系统。

使固定

确保您的sshd_config包含Subsystem配置,如以下文章中所述:
https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ssh-remoting-in-powershell-core

修改sshd_config ,您还需要重新启动 Windows 实例上的 SSH 守护进程: Restart-Service -Name sshd

立即关闭,因为我找到了修复程序。 这纯粹是为了社区文档目的而发布的,所以其他人可以从我的学习中受益。

Issue-Question Resolution-Answered

所有3条评论

sshd_config 位于 %ProgramData%ssh 而不是安装 OpenSSH 的位置。

添加子系统后问题仍然存在,运行'sshd -T'表明我的配置已经加载:

PS> sshd -T | select-string 'subsystem'

subsystem sftp sftp-server.exe
subsystem powershell c:\pwsh\pwsh.exe -sshs -NoLogo -NoProfile

ssh cmd 仍然无法找出名称“powershell”:

PS> ssh [email protected] -s powershell
Authorized users only. All activity may be monitored and reported.
Password:
subsystem request failed on channel 0

操作系统:

PS>((Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\Windows nt\CurrentVersion\" -Name ProductName).ProductName)
Windows 7 Professional

我的 openssh 版本是

PS>((Get-Item (Get-Command sshd).Source).VersionInfo.FileVersion)
7.7.2.0

Powershell 版本

PS> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Microsoft Windows 6.1.7601 S
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

子系统 powershell pwsh.exe -sshs -NoLogo -NoProfile

此页面是否有帮助?
0 / 5 - 0 等级