Powershell: Remoting: Win 10 to RHEL 7 | PS 7.0.3

Created on 27 Jul 2020  路  5Comments  路  Source: PowerShell/PowerShell

I had an issue with remoting and found two similar issues:
https://github.com/PowerShell/PowerShell/issues/12635 and https://github.com/PowerShell/PowerShell/issues/12654

Those are only with PSSession. i had what appears the same on Invoke-Command

Both Error out on Exit with
OpenError: [pingui] Closing the remote server shell instance failed with the following error message : SOAP-ENV:Receiverwsman:InternalError For more information, see the about_Remote_Troubleshooting Help topic.

This prevents the return on Invoke-Command that is needed for the script i am trying to write for automation

Reproduction Steps :: PSSession

$psso = New-PSSessionOption -SkipCACheck -SkipRevocationCheck -SkipCNCheck # this is done for lab env. will not be needed in actual env
$cred = Get-Credential
Enter-PSSession -ComputerName pingui -Credential $cred -Authentication basic -UseSSL -SessionOption $psso
pgrep -f /app/pingidentity/pingaccess/jdk/current/bin/java | wc -l
Exit-PSSession

Reproduction Steps :: Invoke-Command
$findPA = "pgrep -f /app/pingidentity/pingaccess/jdk/current/bin/java | wc -l"
$psso = New-PSSessionOption -SkipCACheck -SkipRevocationCheck -SkipCNCheck # this is done for lab env. will not be needed in actual env
$cred = Get-Credential
$pa1 = Invoke-Command -ComputerName pingui -Credential $cred -Authentication basic -UseSSL -SessionOption $psso -ScriptBlock { $findPA }

Example Output:

PS C:\temp\EYSAFEPISCT> $pa1 = Invoke-Command -ComputerName pingui -Credential $cred -Authentication basic -UseSSL -SessionOption $psso -ScriptBlock { $findPA }
OpenError: [pingui] Closing the remote server shell instance failed with the following error message : SOAP-ENV:Receiverwsman:InternalError For more information, see the about_Remote_Troubleshooting Help topic.
PS C:\temp\EYSAFEPISCT>

I'm not sure what else is needed. please let me know.

Win 10 PS:
PS C:\temp\EYSAFEPISCT> $psversiontable

Name Value
---- -----
PSVersion 7.0.3
PSEdition Core
GitCommitId 7.0.3
OS Microsoft Windows 10.0.17763
Platform Win32NT
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0鈥
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

PS C:\temp\EYSAFEPISCT>

RHEL PS:
[[email protected]: /app/pingidentity/pingaccess/panode]
$ rpm -qa | grep -i psrp
omi-psrp-server-1.4.2-2.x86_64
[[email protected]: /app/pingidentity/pingaccess/panode]
$ rpm -qa | grep -i power
powershell-7.0.3-1.rhel.7.x86_64
[[email protected]: /app/pingidentity/pingaccess/panode]
$

hopefully there is an issue with what i did as suggested by oneof the previous. otherwise i hope this helps find the issue and resolve it from those whom are more familiar with powershell

Issue-Question

All 5 comments

If you are targeting a Linux host you should really be using SSH as the transport. The OMI components seem to be deprecated and not really that stable so you will get a much better experience by using SSH which is much more stable on the Linux platforms.

Hi Jordan,

In searching google i have not found instructions on setting windows to use SSH, just the Linux to have powershell 7.0.3 and the psrp package. Do you have instructions to get windows to use SSH? I will try searching again, but i suspect that this may be a problem for a number due to lack of proper documentation.

Thank you in advance,

Josh

EDIT: limiting to docs.microsoft.com for the search i found: https://docs.microsoft.com/en-us/powershell/scripting/learn/remoting/ssh-remoting-in-powershell-core?view=powershell-7

for some reason i didnt find this previous to today

Yep you effectively need to do

  • Install PowerShell 6+ on Windows to enable SSH transport as a client
  • Install OpenSSH as a client on Windows using that link you shared, the server bits are only required on the Windows host if you want to do Linux -> Windows
  • Set up OpenSSH as a server on the Linux host
  • Add the pwsh subsystem into the sshd_config on the Linux host
# Requires root to edit /etc/ssh/sshd_config
echo "Subsystem powershell $(which pwsh) -sshs -NoLogo" >> /etc/ssh/sshd_config

If you are trying to do some automation for this you also want to set up key based authentication and not use passwords but there are plenty of guides on how to do that for SSH and it's not strictly related to PowerShell. When connecting using the -HostName and not the -ComputerName parameter for Invoke-Command/Enter-PSSession as that will use SSH and not WinRM.

Jordan,

thank you. adding Open SSH to my Win 10 and adding the sshd config update. I'll start with testing username/password but probably will go to key based.

I'll also report back if this is successful so that those whom come after me will know. Hopefully i caan give a quick step by step what i did. not sure i wrote enough but will try.

-Josh

Hi Jordan, and anyone who finds this and is looking for PS Remoting Windows to Linux Help.
It is working for me now.

First get your PowerShell Installed:
WIndows: Use the msi right for you. i suggest the latest stable release of PowerShell 64 bit.
For LInx, this may assist: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-7

I used RedHat as i need to for work. the commands:

Register the Microsoft RedHat repository

curl https://packages.microsoft.com/config/rhel/7/prod.repo | sudo tee /etc/yum.repos.d/microsoft.repo

Install PowerShell

sudo yum install -y powershell

Verification:

Start PowerShell

pwsh

If you can login as root, backup the /etc/ssh/sshd_config
then i echo'd in a variation of Jordan's command:
echo "# For PowerShell" >> /etc/ssh/sshd_config
echo "Subsystem powershell $(which pwsh) -sshs -NoLogo" >> /etc/ssh/sshd_config

Next i checked for OpenSSH in Windows: Get-WindowsCapability -Online | ? Name -like 'OpenSSH*'
as i needed the client and server, but only really need the client as my use is Win to Lin: Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

then i used the invoke and enter with the hostname versions. note: most of what i had is based on winRM and thus the commands look more like

Enter-PSSession -HostName pingui.lab.ey -UserName a1234567-3
pgrep -f /app/pingidentity/pingaccess/jdk/current/bin/java | wc -l
Exit

and

$paFind = Invoke-Command -HostName pingui.lab.ey -UserName a1234567-3 -ScriptBlock { pgrep -f /app/pingidentity/pingaccess/jdk/current/bin/java | wc -l }

@jborean93 thank you again for the assist!

-Josh

Information about installing PowerShell on various Linux distributions
Was this page helpful?
0 / 5 - 0 ratings