OpenSSH on Windows: How to Get it Set Up

The future is now. SSH isn’t just for Linux anymore. With the latest Win32 port of OpenSSH, we can now run OpenSSH on Windows with little effort. This post is a text form of my TechSnips video. If you’d rather watch a video walkthrough, I highly encourage you to check that out.

The code I will be using in this demo is available on GitHub in the TechSnips SnipScripts repository.

Installing OpenSSH on Windows

First, make sure to download the latest release of Win32-OpenSSH. Now that that is downloaded, let’s get started with the demo.

I’m going to set some variables for the location of the OpenSSH on Windows zip file and the location where I want to install the OpenSSH files. I’m going to use c:\Program Files\OpenSSH.

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!.

Next, we need to extract the file to the install path.

Once that is complete, we are ready to install OpenSSH on Windows. To do so, we need to run the install-sshd.ps1 script from the install directory.

Run the OpenSSH on Windows install script

This script will create 2 SSH services which we will use in a minute (ssh-agent and sshd)

Configuring OpenSSH on Windows

But first, let’s go ahead and add an exception to the Windows Firewall for port 22 so that SSH traffic will be allowed through.

Now we need to configure the OpenSSH on Windows services. As you can see when we run Get-Service, The services are currently stopped.

View the OpenSSH on Windows services that were installed

So, let’s set the StartupType of both services to Automatic then start the services.

Running the netstat command we can see that the machine is now listening on Port 22.

Netstat shows that OpenSSH on Windows is listening on port 22

Connecting to Our OpenSSH on Windows Server

Next, I’m going to open up my SSH client, PuTTY and connect to the SSH service running on my localhost.

PuTTY connection to local Windows host over SSH

Accept host key message

SSH connection to Windows with OpenSSH

When prompted to accept the host key, choose Yes. This will open an OpenSSH on Windows session in a Command Prompt. If you would like to have SSH sessions open up in a PowerShell prompt, you will need to add an entry in the registry to define the Defaultshell and specify the location of the PowerShell executable.

Now that we have defined the default shell, when we open a new SSH session, you will notice that the Prompt has changed to a “PS” prompt.

PowerShell running through SSH connection with syntax highlighting and tab completion

You will also notice that tab completion and syntax highlighting both work over SSH as well.

Once you’ve set up OpenSSH on Windows and you’re using PowerShell, I encourage you to check out my other post on How to Configure OpenSSH on Windows for PowerShell Remoting Over SSH.

2 Replies to “OpenSSH on Windows: How to Get it Set Up”

  1. Great article! Thank you!

    How does this version of OpenSSH differ from the OpenSSH distributed by Microsoft as part of Windows 10 version 1803 update?

    1. Well I actually haven’t played around with the one being distributed yet. But from what I can see, it’s the same Win32-OpenSSH bits except they are only installing the client stuff. No sshd server. In my video and post on configuring OpenSSH for PowerShell Remoting over SSH, I mentioned that ssh.exe needs to be in your PATH. With this update, %SYSTEMROOT%\System32\OpenSSH\ is now in your PATH so that step could be skipped. However the version of OpenSSH that gets installed in Windows 10 is running at version 7.6. If you want to use any of the latest updates to the Win32-OpenSSH project, you’ll need to install that and use that ssh.exe instead.

Leave a Reply

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