PowerShell SSH Remoting Linux to Windows

Setup PowerShell SSH Remoting in PowerShell 6

With PowerShell version 6, Microsoft introduced PowerShell Remoting over SSH, which allows true multiplatform PowerShell remoting between Linux, macOS and Windows. PowerShell SSH Remoting creates a PowerShell host process on the target machine as an SSH subsystem. Normally, PowerShell remoting uses WinRM for connection negotiation and data transport, however WinRM is only available on Windows based machines.

There are also some downsides to it. SSH-based remoting doesn’t currently support remote endpoint configuration and JEA (Just Enough Administration). It is also important to understand, that this is not just another PowerShell SSH client.

Use SSH Transport with PowerShell Remoting

To use PowerShell remoting with SSH you can use the same cmdlets, you know from PowerShell remoting with WinRM.

  • New-PSSession
  • Enter-PSSession
  • Invoke-Command

There are 3 new parameters for these cmdlets, if you are using PowerShell SSH remoting.

  • -HostName (Instead of -Computername, you define the SSH target)
  • -UserName (Instead of -Credentials you use the -UserName parameter)
  • -KeyFilePath (If you are using SSH key authentication you can use the -KeyFilePath parameter to point to the key file)

Setup PowerShell SSH Remoting

To work with PowerShell SSH, you will need to complete the following steps on all systems and machines.

  • Install OpenSSH Server and Client
    • OpenSSH for Windows is available directly in Windows 10 (1809) and Windows Server 2019 as an optional feature.
    • On Linux you install OpenSSH depending on your platform
  • Install PowerShell 6 on all systems
  • Configure the SSH subsystem to host a PowerShell process on the remote machine
  • Configure password or key-based authentication

Step by step setup SSH remoting on Windows

Step 1: First you will need to install PowerShell 6 on Windows. You can follow my blog post to easily install PowerShell 6.

Install PowerShell 6

Step 2: Install OpenSSH Client and Open SSH Server. To install client and server and initially configure the OpenSSH server, you can use the following command.

Step 2.1: Since there is currently a bug in OpenSSH for Windows, the path do not accept spaces. You need to create a symlink to a directory without spaces. Run the following command on the target system.

Step 3: Configure and edit the sshd_config file located at $env:ProgramData\ssh on the target machine.

Edit sshd_config

Check that password authentication is enabled

Add the Subsystem for PowerShell

Optional enable key authentication

If you are interested in setting up key based authentication with OpenSSH on Windows Server, check out the blog post on ITOpstalk.com by Orin Thomas (Microsoft Cloud Advocate).

Step 4: Restart the sshd service

Step by step Setup SSH remoting on Linux (Ubuntu 18.04)

Step 1: First you will need to install PowerShell 6 on Linux. You can follow my blog post to easily install PowerShell 6.

Install PowerShell 6 Linux

Step 2: Install OpenSSH Client and Open SSH Server. To install client and server and initially configure the OpenSSH server, you can use the following commands.

Step 3: Configure and edit the sshd_config file at location /etc/ssh on the target machine.

Check that password authentication is enabled

Add the Subsystem for PowerShell

Optional enable key authentication

Step 4: Restart the sshd service

SSH Remoting with PowerShell 6

Now you can start using PowerShell SSH remoting to connect even from different operating systems like Windows to Linux or Linux to Windows. PowerShell 6 SSH Remoting

As mentioned before, you can use the same commands as you are familiar with like New-PSSession, Enter-PSSession or Invoke-Command.

PowerShell SSH Remoting Linux to Windows

As a client you can also use the Azure Cloud Shell, which runs PowerShell 6

Of course, you can also use the PowerShell SSH remoting to connect from Linux to Linux and Windows to Windows. You can find more information about PowerShell SSH remoting on the Microsoft Docs pages. If you have any questions, please let me know in the comments.