How to Configure OpenSSH on Windows for PowerShell Remoting Over SSH

This article is meant to bridge the gap between my video on How to Set Up OpenSSH on Windows and Ethan Bell’s How to Use PowerShell Remoting Over SSH. After installing OpenSSH on Windows, there are a few settings that need to be configured on the client as well as the remote SSH server in order to allow PowerShell Remoting over SSH.

If you try to create a new PSSession over SSH after installing OpenSSH, you may see the following error:

Are you an IT pro ready to take your career to the next level? If so, join our contributor program! You don't have to be an expert presenter, a Microsoft MVP or even have a blog. We want your knowledge! You will be coached on presentation skills, become a member of our awesome community and get paid some nice side hustle income every, single month! Sign up today!.

First, we need to make sure that the path to the ssh.exe executable is in the PATH environment variable on the computer that you will be using to connect to a remote SSH server. To do this, click on the Start button and search for advanced system settings then click on View Advanced System Settings.

Then, click on the Environment Variables button in the System Properties windows.

Select Path from the System Variables list and click Edit.

On the Edit Environment Variable window, click New then enter the path where the ssh.exe executable resides. In my case, this path is C:\Program Files\OpenSSH.

Click OK twice to save the new value.

Open a new PowerShell 6 console so the new PATH change can take effect and let’s retry the connection again. You will notice that we are now being prompted for a password. That looks promising. But when we enter the password, we’re presented with another error:

This is because we haven’t specified the subsystem we want PowerShell to use when connecting over SSH. This is specified in the ssh_config folder on the remote server. This is located under c:\ProgramData\ssh\.

Under the override default of no subsystems section of the ssh_config file, we need to add a line that specifies the location of the pwsh.exe executable. However, OpenSSH doesn’t handle spaces in file paths well, so we need to create a Symbolic link on the c:\ drive and point it to the location of the pwsh.exe executable.

Now we’re ready to update the ssh_config file. On the remote server, open the ssh_config file under c:\ProgramData\ssh\. Under the override default of no subsystems section add the following line.

Save the ssh_config file then restart the SSH services on the remote server.

Now, let’s try to open a PSSession again.

Success!! Now let’s go ahead exit that session and verify that we are in fact connecting through SSH to the remote server by using New-PSSession.

We can see under transport that the session is connecting over the SSH protocol. If we compare that to using New-PSSession with the original –ComputerName parameter, we can see that is using the WSMan protocol.

One Reply to “How to Configure OpenSSH on Windows for PowerShell Remoting Over SSH”

Leave a Reply

Your email address will not be published. Required fields are marked *