Open Source PowerShell – Part 4

Doctor Scripto

Summary: Install and Configure SSH for Open Source PowerShell remoting.

Hey, Scripting Guy! Question With PowerShell, up to this point, one thing that I love is the ability to connect various systems in my environment and run cmdlets on them remotely.  Can we do this with Open Source PowerShell?

Hey, Scripting Guy! Answer Honorary Scripting Guy, Sean Kearney, is here today to go over how to get Open Source PowerShell set up to do remoting.  Because this, my friends, this is the big game changer.

When Linux admins presently need to work with a Windows Server, they need to play with a few options:

  • Remote desktop (RDP) to the server
  • Install Secure Shell (SSH) and run an SSH session to the Windows computer
  • Install a third-party solution such as VNC on the Windows computer

A Windows admin could typically just download a utility like Putty and hop off to work.  However, both of these solutions are limited because they lack a key piece in automation.

When you run a script against either system, you can only visually see the status code that the application produced or perhaps lines of red on the screen.

There is no built-in way for a Linux admin to easily run a Windows PowerShell script and have the value passed back to Bash to allow them to action up it. It is a similar issue for Windows admins when they run Bash scripts remotely. The Windows computer does not have a simple way to see that the script produced an error code of say, -3.

With Open Source, PowerShell remoting was one of the big pieces to change this scenario and level the playing field. The requirements on both end points (Linux/macOS and Windows) are pretty simple.

  • SSH client and server
  • Open Source PowerShell
  • Appropriate firewall ports opened

In Linux and in Windows, just install Open Source PowerShell according to the instructions on Github under ‘Get PowerShell’.

On the Linux and macOS side, you’ll need to make sure you are running openssh-client and openssh-server. For the Windows side, you need to download and install Win32 Open SSH, which is a port of openssh for Windows.

After it’s installed, you need to configure the endpoints. On Windows, you’ll need to open up and edit the sshd_config file in the C:\Program Files\OpenSSH folder and make the following changes.

Find the following lines in the file, and edit them to reflect the following values. (Remove the # preceding the value if needed,)

PasswordAuthentication yes

RSAAuthentication yes

PubkeyAuthentication yes

You’ll also need to find the following line.

Subsystem        sftp       C:/Program Files/OpenSSH/sftp-server.exe

Add this line directly below it.

Subsystem         powershell C:/Program Files/PowerShell/ -sshs -NoLogo -NoProfile

Of course, you’ll need to make sure this path matches the install location for your release of Open Source PowerShell.  After that’s done, restart the sshd service in Windows. In PowerShell, you can simply execute.

Restart-Service sshd

In Linux and macOS, you’ll make similar edits to the local sshd_config file.

PasswordAuthentication yes

RSAAuthentication yes

PubkeyAuthentication yes

And instead of this value:

Subsystem         powershell C:/Program Files/PowerShell/ -sshs -NoLogo -NoProfile

In Linux and macOS, you won’t need to supply the path to PowerShell. (Presently, you have two versions on Windows, and we need to explicitly target the Open Source version,) The value will look like this.

Add this line directly below it.

Subsystem         powershell powershell -sshs -NoLogo -NoProfile

Restart that Daemon in Linux using the following command

sudo service ssh restart

When you’re done, you should be able to connect to Windows from Linux by using any standard client and vice versa.

So, you’ve got SSH running on both endpoints. Now what?

Next Friday, we show you the coolest thing ever. Running PowerShell remoting over SSH and actively running and receiving the status of scripts from either side!

I invite you to follow the Scripting Guys on Twitter and Facebook. If you have any questions, send email to them at, or post your questions on the Official Scripting Guys Forum. See you tomorrow.

Until then, always remember that with Great PowerShell comes Great Responsibility.

Sean Kearney Honorary Scripting Guy Cloud and Datacenter Management MVP


Discussion is closed.

Feedback usabilla icon