The OpenSSH Client and OpenSSH Server are separately installable components in Windows Server 2019 and Windows 10 1809.Users with these Windows versions should use the instructions that follow to install and configure OpenSSH.
Note
Users who acquired OpenSSH from the PowerShell Github repo (https://github.com/PowerShell/OpenSSH-Portable) should use the instructions from there, and should not use these instructions.
Installing OpenSSH from the Settings UI on Windows Server 2019 or Windows 10 1809
MobaXterm X server and SSH client MobaXterm is your ultimate toolbox for remote computing. In a single Windows application, it provides loads of functions that are tailored for programmers, webmasters, IT administrators and pretty much all users who need to handle their remote jobs in a more simple fashion. PuTTY has long been the most popular SSH client used on Windows, but since the last major update, Windows 10 now comes with an SSH client preinstalled. It’s easier and faster to use this client rather than installing and configuring PuTTY. How to Install Windows’ OpenSSH Client. First, check if it’s already installed.
OpenSSH client and server are installable features of Windows 10 1809.
To install OpenSSH, start Settings then go to Apps > Apps and Features > Manage Optional Features.
Scan this list to see if OpenSSH client is already installed. If not, then at the top of the page select 'Add a feature', then:
- To install the OpenSSH client, locate 'OpenSSH Client', then click 'Install'.
- To install the OpenSSH server, locate 'OpenSSH Server', then click 'Install'.
Once the installation completes, return to Apps > Apps and Features > Manage Optional Features and you should see the OpenSSH component(s) listed.
Note
Installing OpenSSH Server will create and enable a firewall rule named 'OpenSSH-Server-In-TCP'. This allows inbound SSH traffic on port 22.
Installing OpenSSH with PowerShell
To install OpenSSH using PowerShell, first launch PowerShell as an Administrator.To make sure that the OpenSSH features are available for install:
Then, install the server and/or client features:
Uninstalling OpenSSH
To uninstall OpenSSH using the Windows Settings, start Settings then go to Apps > Apps and Features > Manage Optional Features.In the list of installed features, select the OpenSSH Client or OpenSSH Server component, then select Uninstall.
To uninstall OpenSSH using PowerShell, use one of the following commands:
A Windows restart may be required after removing OpenSSH, if the service is in use at the time it was uninstalled.
Initial Configuration of SSH Server
To configure the OpenSSH server for initial use on Windows, launch PowerShell as an administrator, then run the following commands to start the SSHD service:
Initial use of SSH
Once you have installed the OpenSSH Server on Windows, you can quickly test it using PowerShell from any Windows device with the SSH Client installed.In PowerShell type the following command:
The first connection to any server will result in a message similar to the following:
The answer must be either “yes” or “no”.Answering Yes will add that server to the local system’s list of known ssh hosts.
You will be prompted for the password at this point. As a security precaution, your password will not be displayed as you type.
Once you connect you will see a command shell prompt similar to the following:
The default shell used by Windows OpenSSH server is the Windows command shell.
Buried in the list of optional features that can be installed in Windows 10 are the beta versions of a OpenSSH Client and an OpenSSH Server. The client allows you to connect to remote SSH servers directly from the Windows command line and the server allows remote users to to remotely connect to Windows 10 and receive a command prompt over SSH.
For those who would like remote console access to their Windows 10 computers, the built-in Windows 10 OpenSSH Server may be what you are looking for. Even better, for those who are familiar with OpenSSH from using it in Linux, the Windows 10 version operates pretty much the same.
While the Windows 10 OpenSSH client is really easy to install and use. figuring out how to get the OpenSSH Server up and running was a real pain as you have to do a lot of undocumented changes to permissions & privileges and the key generation doesn't work as expected. Now that I have figured it all out, though, it should take you no more than 10 minutes to follow these instructions and install a working OpenSSH Server implementation in Windows 10.
Installing the Windows 10 OpenSSH Server
The first step is to click on the Windows Start Menu () and then in the search field type option. A search result labeled Manage optional features will be displayed, which you should click on. This will open up the Manage optional features screen as shown below.
This screen shows all the currently installed optional Windows features. Now click on the Add a feature button as indicated by the red arrow above. This will open up a list of optional features that can be installed. Most of them are font packs, but if you scroll down, you will see a feature called OpenSSH Server (Beta).
To install the OpenSSH Server (Beta), simply select it and click on the Install button. Once you click on the Install button, you will see the feature disappear from the list. This is normal and nothing to be worried about. Just click on the back arrow in the upper left of the window and you will be back to the list of installed features, but now with the OpenSSH Server (Beta) installed.
You can now close this window.
After the installation, two new Windows services called sshd and sshd-agent will have been created and the associated files will be stored in the folder C:WindowsSystem32OpenSSH. The list of installed files are:
In order to finish the installation, you should now reboot your computer.
After you log back in, the sshd service will not be started and if you try to start it, Windows will report it does not have the required privileges for the service to start.
The missing privilege that the service needs is Replace a Process Level Token and we have to add it to the NT Servicesshd account. To do that, open the Local Security Policy Editor by searching for secpol in the Start Menu and selecting the Local Security Policy result that appears.
When the Local Security Policy Editor opens, you should expand Local Policies and left click on User Rights Assignment. Once you have selected User Rights Assignment, you will see various privileges in the right pane. Scroll down till you see the Replace a process level token privilege and double-click on it. This will open the properties for that privilege and show the accounts or groups that it is currently assigned to.
Now click on the Add User or Group button and enter NT Servicesshd into the Enter the object names to select field as shown below.
When done, click ok the OK button to give this privilege to sshd. You can then press the OK button to close the properties and then close the Local Security Policy editor.
Even with the privilege enabled, when you try to start the sshd service, Windows will display the error 'Windows could not start the sshd service on Local Computer. Error 1067: The Process terminated unexpectedly.'
If you look in the C:WindowsSystem32OpenSSHLogssshd.log file it will display errors like the following.
SSHD is displaying these errors because you have not generated the host keys that will be used to encrypt the traffic between the server and client. To create these keys we need to execute the C:WindowsSystem32OpenSSHssh-keygen.exe -A command from an elevated command prompt so that the keys are created in the C:WindowsSystem32OpenSSH folder.
Using the 'ssh-keygen -A' command will generate a key using the default key file path, an empty passphrase, default bits for the key type, and default comment. Normally, I would add a passphrase to the key, but in the current bundled Windows 10 version of OpenSSH , ssh-keygen will respond with a 'failed: invalid argument' error when you try and add a passphrase.
When you run the C:WindowsSystem32OpenSSHssh-keygen.exe -A command, it will generate a private key named ssh_host_ed25519_key and a public key named ssh_host_ed25519_key.pub in the C:WindowsSystem32OpenSSH folder.
When ssh-keygen is finished creating and saving your key, it will bring you back to the command prompt as shown above. You can type exit and press enter to exit the elevated command prompt.
Unfortunately, we are not done yet and if you try to start the sshd service, Windows will again respond with an 'Error 1067'. This is because the NT Servicesshd account does not have access to the C:Windowssystem32OpenSSHssh_host_ed25519_key file. To fix this, go into the properties of the ssh_host_ed25519_key file and make the following changes:
- Change the owner of the file to NT Servicesshd.
- Give the NT Servicesshd only the Read permission to this file.
- Remove permissions for all users to this file. For example, your logged in account will have permissions, which should be removed.
When done, your permissions on the ssh_host_ed25519_key file should look like:
If you do not set the permissions correctly, you will not be able to start the sshd service and the log file will display the following errors:
When you have the proper permissions set on the private key file, you can start the sshd service again. This time, though, the sshd service will start and be available for computers to connect.
Now that the service is running you can remotely connect to your Windows 10 box over SSH. Below is an example of what it looks like when you SSH into a Windows 10 computer. Notice that you get a full command prompt where you can run all command line tools, including PowerShell.
The sshd service is to Automatic (Delayed Start), which means that Windows will launch this service after all other services which are set to Automatic have finished starting. Therefore, after you reboot a computer it may take a few minutes before the OpenSSH Server is up and running and can be connected to.
With an OpenSSH Server running on Windows 10, you have added an extra layer of flexibility with how you can manage a computer. If you do decide to enable the OpenSSH Server, make sure that port 22, which sshd listens on, is only accessible by trusted IP addresses.