PowerShell Remoting over SSH fails Windows client

Created on 13 Oct 2016  路  24Comments  路  Source: PowerShell/PowerShell

When initiating a New-Pssession from Windows to Linux or Windows to Windows the following error occurs
New-PSSession : [eotsrv2016] An error has occurred which Windows PowerShell cannot handle. A remote session might have
ended.
At line:1 char:4

  • $s=New-PSSession -HostName eotsrv2016 -UserName administrator
  • ~~~~~~~~~~~~~~

    • CategoryInfo : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [New-PSSession], PSRemotin

      gDataStructureException

    • FullyQualifiedErrorId : PSSessionOpenFailed

      Steps to reproduce

      ------------------

      Current PowerShell alpha 10 build on Ubuntu 16 and Server 2016 RTM

      OpenSSL on Linux win32_ssl on Server

Expected behavior

PSremoting session initiated after authentication completed

Actual behavior

Error thrown by PowerShell 6.0 / Alpha 10

Environment data

Name Value


PSEdition Core
PSVersion 6.0.0-alpha
WSManStackVersion 3.0
BuildVersion 3.0.0.0
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0...}
GitCommitId v6.0.0-alpha.10
PSRemotingProtocolVersion 2.3
CLRVersion
SerializationVersion 1.1.0.1


Resolution-Fixed WG-Remoting

All 24 comments

Further details. I ran the sshd -d on the Windows server and on Linux. It does not appear that the SSH agent is ever initiated when this error occurs.

If I do an SSH.exe from Windows to Linux or Windows to Windows using the SSH_win32 on Server 2016, all is successful. I can even successfully connect from Linux to Windows using SSH. But I cannot seem to get PowerShell 6 / .10 to receive or connect (Port 22 is open on the Windows Firewall)

I found the root cause. In firing up Process Monitor (Even tho 'C:Program FilesOpenSSH' is in the System search path) PowerShell 6 (.9 and .10 release) is not searching for it there.
It checks the following paths (Confirmed using procmon.exe as Admin)

Note on this server... I do NOT have Putty installed but it searches for that path entry suggesting something is hard coded
It searches for SSH.EXE and Get-SSH.EXE

C:Windowssystem32
C:Windows
C:Windowssystem32wbem
C:Windowssystem32WindowsPowerShell1.0
C:Program Files (x86)Putty
C:UsersAdministratorAppdataLocalMicrosoftWindowsApps

The workaround I am seeing is to copy the ssh.exe into ANY one of these folders (which is NOT the correct solution... just a workaround)

Per https://github.com/PowerShell/PowerShell/tree/master/demos/SSHRemoting you need to make sure ssh.exe is found in your path

Hum! In my situation. I got my Windows 10 VM to connect to my physical Linux machine. But I'm not been able to do Linux to Windows yet.

Windows to Linux
enter-possession -hostname 10.0.0.6 -username maxt (enter password and answer yes to the key signature for ssh)

This works!

Trying to get Linux to Windows.

@MaximoTrinidad did you make the changes to sshd_config on Windows to add the powershell subsystem?

I had to rollback to PowerShell 6 release 9 and older SSH_win32 to receive on Windows. Linux version unchanged

@SteveL-MSFT I actually have it in the System path. The problem is 'C:Program Files (x86)Putty' is NOT part of the system path and ALSO not an installed application. This means a hard coded entry somewhere.

the expected results would be that PowerShell 6 when trying to launch SSH.exe searches the SYSTEM path (if it is there might be a bug in how it's going about it) because it should never be looking for "putty" when the app doesn't exist anywhere on the server or the system.

But copying the SSH.exe into a searched folder (the ones PowerShell 6 is looking at) provides a workaround.

Also creating a Symbolic Link to 'Program Files (x86)putty' and targeting the 'C:Program FilesOpenSSH' also works

@SteveL-MSFT I also got the same SSHD_Config that Jason Helmick used on his VM. His configuration was identical to mine.

@energizedtech Neither OpenSSH nor PowerShell should have any dependency on Putty. I just searched the code for both and Putty doesn't come up (well, came up once in OpenSSH in a comment). Which process is searching the Putty path?

@SteveL-MSFT Aha! Not PowerShell! Server 2016 may be at fault! (Turns out in the last 15 mins I installed Putty)

The new Path Editor in Server 2016 allows you to "Browse" for a folder. But it does not add on the '' at the end of the folder path. Testing now with this change.

I did all the changes to both Windows and Linux sshd_config files. I may need to verify the Linux file. But at least got Windows to Linux PowerShell 6.0.0-Alpha10 working.

windowstolinux

Yep! That's the issue. In Server 2016 if you browse for a folder in the Path editor the search may not work properly because it drop the second ''

@maximotrinidad Try editing your Server 2016 System path. Make sure you have a '' at the end. The editor did that mess to me

Sean! Wait! So, you are using Putty to connect to a terminal session to Linux and then you're opening PowerShell? Right. I not using Putty at all,

@maximotrinidad No Putty is on there for a totally different purpose. Check you System Path and make sure the entry for OpenSSH looks like this
C:Program FilesOpenSSH <---- watch that is has the SECOND back slash... mine didn't

@maximotrinidad Oh.... _doh_ ... yes.... I am using Putty as my "Terminal for Linux" :) Sorry!

Sean,
I'm using straight PowerShell Alpha10 to connect to my linux box using Enter-PSSession cmdlet which is pretty cool. Thanks for the tip for Putty. I will try that one later!
:)

@SteveL-MSFT So the "root cause" actually seems to be that the entry in the System Path is there but it's missing a trailing '' which causes either Windows or PowerShell to skip the entry :)

Well! What a tryout with Windows Server 2016 GA for remoting.
First, I had to use Windows PowerShell 5.1 in order to install Chocolatey, The "Install-Package Chocolatey" didn't work in PowerShell Core Alpha10 nor in Windows PowerShell 5.1.

But I could use the cmd line in Windows PowerShell 5.1: (iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))

After I was able to install OpenSSH-Win32, configure the sshd_config file and firewall rule on the Windows Server, then I was able only connect from Windows Server 2016 GA (VM) to my Ubuntu 16.04.1 desktop.

Now, it seems the first time you connect to a system, the connection will fail. The second time you try it will work.

So, I was able to connect via OpenSSH-Win32 PowerShell Windows to Linux. Now, this time I think I got close to have Linux to Windows connectivity (see image below).

I don't know what I'm missing to make Linux connect to Windows.

w2k16tolinux

Sorry! Here's the error message I'm getting the try Enter-PSSession -hostname 10.0.0.26 -username Administrator

PS /home/maxt> Enter-PSSession -HostName 10.0.0.26 -UserName Administrator
Enter-PSSession : The background process reported an error with the following
message: The SSH client session has ended with error message: ssh: connect to
host 10.0.0.26 port 22: Connection timed out.
At line:1 char:1

  • Enter-PSSession -HostName 10.0.0.26 -UserName Administrator
  • ~~~~~~~~~~~~~~~

    • CategoryInfo : ResourceUnavailable: (:) [Enter-PSSession], PSRe

      motingTransportException

    • FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemoting

      DataStructureException,Microsoft.PowerShell.Commands.EnterPSSessionCommand

linuxtowindowserr

I decided the open a different thread for the Linux to Windows remoting incident:
Remoting Linux to Windows fail after password #2473

@energizedtech , I will try installing Putty next. Thanks for the tip. I will comment later.

@MaximoTrinidad As I mentioned in your separate issue thread this is an SSH client error indicating the Windows machine is not reachable. Please see that thread for more information.

@energizedtech When you get errors like you did at the top of this thread, always take a close look at the error record. Many times it will contain an exception object along with inner exception objects that provide more information about the error.

Was this page helpful?
0 / 5 - 0 ratings