Remoting on Linux

Microsoft provides instructions for installing PowerShell on Linux; these should be followed before attempting to configure remoting: https://docs.microsoft.com/en-us/powershell/scripting/install/installing-powershell-core-on-linux?view=powershell-6.

Once installed, it is possible to make PowerShell the default shell. This is optional and does not affect remoting. First, check that PowerShell is listed in the shells file:

Get-Content /etc/shells   # Use cat or less in Bash

The native chsh (change shell) command can be used to change the default shell for the current user, as shown in the following example:

chsh -s /usr/bin/pwsh

To configure remoting using WSMan, the OMI and PSRP packages must be installed. The following example uses yum since the operating system in use is CentOS 7:

yum install omi.x86_64 omi-psrp-server.x86_64

By default, CentOS has a firewall configured. The network interface in use, in this case eth0, must be added to an appropriate zone, and WinRM must be allowed:

firewall-cmd --zone=home --change-interface=eth0
firewall-cmd --zone=home --add-port=5986/tcp

Once configured, it should be possible to connect to the remote host. SSL is required to form the connection. The certificate is self-signed so certificate validity tests must be skipped at this stage:

$params = @{
ComputerName = 'LinuxSystemNameOrIPAddress'
Credential = Get-Credential
Authentication = 'Basic'
UseSsl = $true
SessionOption = New-PSSessionOption -SkipCACheck -SkipCNCheck
}
Enter-PSSession @params

The state of the certificate leaves the identity of the host in question, but it does ensure that traffic is encrypted. If SSL is to be used beyond testing, a valid certificate chain should be established.

At this point, the remote computer should be accessible using both Windows PowerShell and PowerShell Core.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.22.242.141