Powershell: New-PSSession error "subsystem request failed on channel 0" when using SSH key authentication

Created on 19 Jan 2018  ·  3Comments  ·  Source: PowerShell/PowerShell

Reproduction Steps

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

Symptom

New-PSSession : [x.x.x.x] The background process reported an error with the following message: The SSH client session has ended with error message: subsystem request failed on channel 0.

NOTE: I'm able to successfully SSH into the system using the ssh command line client from Mac.

Fix

Make sure your sshd_config contains the Subsystem configuration as documented in the following article:
https://docs.microsoft.com/en-us/powershell/scripting/core-powershell/ssh-remoting-in-powershell-core

After modifying the sshd_config, you also need to restart the SSH daemon on your Windows instance: Restart-Service -Name sshd.

Closing immediately, as I found the fix. This is being posted purely for community documentation purposes, so others can benefit from my learnings.

Issue-Question Resolution-Answered

All 3 comments

sshd_config is located in %ProgramData%ssh AND NOT where OpenSSH is installed.

The problem keeps existing after I add the Subsystem, run 'sshd -T' shows that my config has already been loaded:

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

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

The ssh cmd still can not figuring out the name 'powershell':

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

operation system:

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

My openssh version is

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

Powershell Version

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

Subsystem powershell pwsh.exe -sshs -NoLogo -NoProfile

Was this page helpful?
0 / 5 - 0 ratings