Contents
I’m thrilled to share that a Beta OpenSSH client and server daemon are available as a Feature-on-Demand in Windows 10 Fall Creators Update and Windows Server 1709. Since our last update blog, we’ve been working hard on a Win32 port of OpenSSH and working closely with members of the OpenSSH Portable and OpenBSD projects with the eventual goal of bringing Win32 support upstream into OpenSSH Portable.
Until then, you should expect OpenSSH support in Windows to continue to improve in future updates of Windows, including upcoming Windows Insider builds. You can track our progress on GitHub where you can find our wiki and the latest builds that include tons of fixes and support for operating systems downlevel to Windows 7 and Server 2008 R2.
Overview
OpenSSH is a collection of client/server utilities that enable secure remote login, remote file transfer, and public/private key pair management. It’s an extremely powerful tool that originated as part of the OpenBSD project, and has been used for many years across the BSD, Linux, macOS, and Unix ecosystems.
Note: The OpenSSH client and server are still very much in Beta, so we do not recommend using them in production environments.
Installation
Great! So how do I install the bits?
Installing with the Settings UI
To install it using the Settings UI, go to Apps -> Apps and Features -> Manage optional features -> Add a feature:
Then select OpenSSH Client (Beta) or OpenSSH Server (Beta) and Install:
Installing with PowerShell
To install OpenSSH using PowerShell, first launch PowerShell as an Administrator.
To make sure that the OpenSSH features are available for install:
1 | <span class="pl-c1">Get-WindowsCapability</span> <span class="pl-k">-</span>Online <span class="pl-k">|</span> <span class="pl-k">?</span> Name <span class="pl-k">-like</span> <span class="pl-s">'OpenSSH*'</span> |
This should return the following output:
1 2 3 4 5 6 | Name : OpenSSH.Client~~~~0.0.1.0 State : NotPresent Name : OpenSSH.Server~~~~0.0.1.0 State : NotPresent |
Then, install the server and/or client features:
1 2 3 4 5 | <span class="pl-c"># Install the OpenSSH Client</span> <span class="pl-c1">Add-WindowsCapability</span> <span class="pl-k">-</span>Online <span class="pl-k">-</span>Name OpenSSH.Client~~~~<span class="pl-c1"><span class="pl-c1">0.0</span></span>.<span class="pl-c1"><span class="pl-c1">1.0</span></span> <span class="pl-c"># Install the OpenSSH Server</span> <span class="pl-c1">Add-WindowsCapability</span> <span class="pl-k">-</span>Online <span class="pl-k">-</span>Name OpenSSH.Server~~~~<span class="pl-c1"><span class="pl-c1">0.0</span></span>.<span class="pl-c1"><span class="pl-c1">1.0</span></span> |
Both of these should return the following output:
1 2 3 4 | Path : Online : True RestartNeeded : False |
Installing with DISM.exe
To install OpenSSH with DISM.exe, first open CMD as an Administrator.
To make sure that OpenSSH features are available for install:
1 | dism /Online /Get-Capabilities <span class="pl-k">|</span> <span class="pl-k">findstr</span> OpenSSH |
This should return the following output:
1 2 3 | Capability Identity : OpenSSH.Client~~~~0.0.1.0 Capability Identity : OpenSSH.Server~~~~0.0.1.0 |
Then, install the server and/or client features:
1 2 | dism /Online /Add-Capability /CapabilityName:OpenSSH.Client~~~~0.0.1.0 dism /Online /Add-Capability /CapabilityName:OpenSSH.Server~~~~0.0.1.0 |
Configuration
Great! You’ve installed OpenSSH. What now?
Configuring the SSH Client (ssh.exe)
Password-based authentication
If you want to use the SSH client with password authentication, no configuration is necessary. Just pop open PowerShell or cmd, and use ssh
to connect to your SSH server:
1 2 3 4 5 6 7 8 | ssh user1@contoso.com <span class="pl-c"># You can also use domain accounts to login</span> <span class="pl-c"># UPN syntax works...</span> ssh user1@domain1@contoso.com <span class="pl-c"># ...as does NetBIOS syntax</span> ssh user1domain1@contoso.com |
Key-based authentication
If you want to use key-based authentication, you first need to generate some public/private key pairs for your client. From PowerShell or cmd, use ssh-keygen
to generate some key files.
1 2 | cd ~.ssh ssh<span class="pl-k">-</span>keygen |
This should output something like:
1 2 3 | Generating public/private ed25519 key pair. Enter file in which to save the key (C:Usersuser1.sshid_ed25519): |
You can hit Enter to accept the default or specify a path where you’d like your keys to be generated. At this point, you’ll be prompted to use a passphrase to encrypt your private key files.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | Enter passphrase (empty for no passphrase): Enter same passphrase again: Your identification has been saved in C:Usersuser1.sshid_ed25519. Your public key has been saved in C:Usersuser1.sshid_ed25519.pub. The key fingerprint is: SHA256:OIzc1yE7joL2Bzy8/gS0j8eGK7bYaH1FmF3sDuMeSj8 user1@CONTOSO@LOCAL-HOSTNAME The key's randomart image is: +--[ED25519 256]--+ | . | | o | | . + + . | | o B * = . | | o= B S . | | .=B O o | | + =+% o | | *oo.O.E | |+.o+=o. . | +----[SHA256]-----+ |
Now you have a public/private ED25519 key pair
(the .pub files are public keys and the rest are private keys):
1 2 3 4 5 | Mode LastWriteTime Length Name ---- ------------- ------ ---- -a---- 11/8/2017 11:09 AM 1679 id_ed25519 -a---- 11/8/2017 11:09 AM 414 id_ed25519.pub |
Your private key files are the equivalent of a password. You should protect them under any and all circumstances. If someone acquires your private key, they can log in to any SSH server as an identity that authorizes the corresponding public key to log in.
For that reason, we should take advantage of ssh-agent
to securely store the private keys within a Windows security context. To do that, we simply start the ssh-agent
service (as Administrator) and use ssh-add
to store our private key. Then, whenever a private key is needed for authentication, ssh-agent
will automatically retrieve your local user’s private key and pass it to your SSH client.
1 2 3 4 5 6 7 8 9 10 11 12 | <span class="pl-c"># Make sure you're running as an Administrator</span> <span class="pl-c1">Start-Service</span> ssh<span class="pl-k">-</span>agent <span class="pl-c"># This should return a status of Running</span> <span class="pl-c1">Get-Service</span> ssh<span class="pl-k">-</span>agent <span class="pl-c"># Now load your key files into ssh-agent</span> ssh<span class="pl-k">-</span>add ~.sshid_ed25519 <span class="pl-c"># Now that it's loaded into ssh-agent,</span> <span class="pl-c"># we don't have to keep the key file anymore</span> <span class="pl-c1">Remove-Item</span> ~.sshid_ed25519 |
Move the contents of your public key (~.sshid_ed25519.pub
) into a text file called authorized_keys
in ~.ssh
on your server/host.
Note: these directions assume your sshd server is a Windows-based machine using our OpenSSH-based server, and that you’ve properly configured it based on the instructions below (including the installation of the OpenSSHUtils
PowerShell module). If you’re using a non-Windows machine, you should replace all remote instances of C:usersuser1
with something like /home/user1
. Additionally, the ACL line should be unnecessary that uses PowerShell should be unnecessary.
1 2 3 4 5 6 7 8 | <span class="pl-c"># Make sure that the .ssh directory exists in your server's home folder</span> ssh user1@domain1@contoso.com mkdir C:usersuser1.ssh <span class="pl-c"># Copy your public key file to authorized_keys on your server</span> scp C:Usersuser1.sshid_ed25519.pub user1@domain1@contoso.com:C:Usersuser1.sshauthorized_keys <span class="pl-c"># Appropriately ACL the authorized_keys file on your server</span> ssh <span class="pl-k">--</span><span class="pl-k">%</span> user1@domain1@contoso.com powershell <span class="pl-k">-</span>c <span class="pl-k">$</span><span class="pl-c1">ConfirmPreference</span> <span class="pl-k">=</span> <span class="pl-s">'None'</span><span class="pl-k">;</span> <span class="pl-c1">Repair-AuthorizedKeyPermission</span> C:Usersuser1.sshauthorized_keys |
Congrats! You should no longer need a password when authenticating as User1
against contoso.com
.
Configuring the OpenSSH Server (sshd)
First, it’s worth noting again that this OpenSSH for Windows is still very much in beta form. It should only be used in safe, testing environments.
To enable authentication into an SSH server on Windows, you first have to generate host keys. As an Administrator:
1 2 3 4 5 6 7 | <span class="pl-c1">Start-Service</span> ssh<span class="pl-k">-</span>agent cd C:WindowsSystem32OpenSSH .ssh<span class="pl-k">-</span>keygen <span class="pl-k">-</span>A <span class="pl-c"># C:WindowsSystem32OpenSSHssh-keygen.exe: generating new host keys: ED25519</span> .ssh<span class="pl-k">-</span>add ssh_host_ed25519_key <span class="pl-c"># Identity added: .ssh_host_ed25519_key (User1@CONTOSO@LOCAL-HOSTNAME)</span> |
Due to certain security requirements, you will also have to install our OpenSSHUtils
helper module to appropriately ACL your host keys. As an Administrator:
1 2 3 4 5 | <span class="pl-c1">Install-Module</span> <span class="pl-k">-</span>Force OpenSSHUtils <span class="pl-c1">Repair-SshdHostKeyPermission</span> <span class="pl-k">-</span>FilePath C:WindowsSystem32OpenSSHssh_host_ed25519_key <span class="pl-c"># Use A or Y as your response to the prompts to set file owners</span> |
Then you can start sshd and your server is ready to go:
1 2 3 4 | <span class="pl-c1">Start-Service</span> sshd <span class="pl-c"># This should return a Status of Running</span> <span class="pl-c1">Get-Service</span> sshd |
Note: currently only the built-in ED25519 authentication key type is supported. In the future, we plan to add support for LibreSSL which will enable additional authentication key types. In the meantime, you can experiment with LibreSSL builds on GitHub.
You may also need to add a firewall rule like this one that allows traffic on port 22 (though your requirements may vary based on your environment, e.g. Domain
might be Private
):
1 | <span class="pl-c1">New-NetFirewallRule</span> <span class="pl-k">-</span>Name sshd <span class="pl-k">-</span>DisplayName <span class="pl-s">'OpenSSH Server (sshd)' -Service sshd</span> <span class="pl-k">-</span>Enabled True <span class="pl-k">-</span>Direction Inbound <span class="pl-k">-</span>Protocol TCP <span class="pl-k">-</span>Action Allow <span class="pl-k">-</span>Profile Domain |
Stay tuned!
Enjoy playing with OpenSSH on Windows, and keep your eyes peeled on the PowerShell blog for upcoming news.