SSH Remote management

Secure Shell (SSH) is a network protocol used connecting to remote computers securely. It is the standard connection mechanism in Unix systems. The PowerShell Core team is actively working on PowerShell remoting over SSH (including a Win32 port of OpenSSH) to support secure connections for both Unix and Windows systems.

As our last remoting example, we will configure a Windows Server to accept PowerShell session over SSH and remotely manage it from a Linux machine.

We will begin by downloading and installing Win32-OpenSSH (https://github.com/PowerShell/Win32-OpenSSH/releases) and copying the files to C:openssh.

As an administrator execute the PowerShell script install-sshd.ps1 included in the folder to install the SSH services. We then generate and secure the SSH host keys for the services:

.install-sshd.ps1
.ssh-keygen.exe -A

.FixHostFilePermissions.ps1 -Confirm:$false

SSH connections commonly use port 22 so you will have to configure your firewall to allow traffic through this port:

New-NetFirewallRule -Protocol TCP -LocalPort 22 -Direction Inbound
-Action Allow -DisplayName SSH

On the OpenSSH folder we will add the following lines to the configuration file sshd_config to allow connections using passwords and install the PowerShell subsystem (the PowerShell executable that will receive the connections):

Subsystem powershell C:/Program Files/PowerShell/6.0.0-beta.4/powershell.exe -sshs -NoLogo -NoProfile
PasswordAuthentication yes

On the client machine we can now establish the connection using the SSHTransport parameter on the New-PSSession command:

PS /root> powershell
PowerShell v6.0.0-beta.4
Copyright (C) Microsoft Corporation. All rights reserved.

PS /root> New-PSSession -HostName testb -UserName admin1 -SSHTransport
admin1@testb's password:

Id Name ComputerName ComputerType State ConfigurationName Availability
-- ---- ------------ ------------ ----- ----------------- ------------
1 SSH1 testb RemoteMachine Opened DefaultShell Available

PS /root> Get-PSSession | Enter-PSSession
[testb]: PS C:Usersadmin1Documents>

These are the most basic scenarios and should enable you to continue experimenting with PowerShell Core. However, there are other scenarios worth exploring. Due to the beta state of the products, it would be very difficult to cover all of these (with all their nuances); we recommend that you review the documentation and follow the progress of the project in GitHub.

In the following examples, we will focus on using the Office 365 API from PowerShell Core.

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

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