Today I’m going to talk about the built in SSH server that can be added to Windows Server 2019. With previous versions of server, there was some detailed configuration and installs you needed to do, to get SSH working on a Windows Server. With Windows Server 2019, it has become much easier. Here are the steps to install, configure, and test:

  1. Open a PowerShell window on the Server you wish to install at:

  2. Run the following command to install the SSH server components:

    Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

  3. The install opens the firewall port and configures the service. Last step is start both SSH services with the following command and set them to automatic:

    Set-Service sshd -StartupType Automatic

    Set-Service ssh-agent -StartupType Automatic

    Start-Service sshd

    Start-Service ssh-agent

  4. Test with SSH client. I used Ubuntu installed on Windows 10 WSL. The format for server on domain to connect is upn of the login account @servername, as in:

ssh This email address is being protected from spambots. You need JavaScript enabled to view it.@servername

  • For servers in a workgroup, use a local admin account@servername as in:

ssh AzureVMAdmin@servername

5. After you login, you receive a command prompt where you can proceed with CMD or open PowerShell:

        

OpenSSH gives you the ability to connect to your windows servers without remote PowerShell and get a full CMD and PowerShell Experience. The ability to connect to Windows machines from Linux with a remote CMD shell is also useful in mixed environments.

In case you’re asking, you also can do the opposite way, and install PowerShell on Linux and remote to a PowerShell Instance on a Linux Machine with PowerShell Core on a Window Machine, but that is for a later post…

 

If you want to install the OpenSSH Client, enter the following:

# Install the OpenSSH Client Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

 

Windows Configurations in sshd_config

In Windows, sshd reads configuration data from %programdata%\ssh\sshd_config by default, or a different configuration file may be specified by launching sshd.exe with the -f parameter. If the file is absent, sshd generates one with the default configuration when the service is started.

To change the default port, edit the sshd_config file, uncomment the Port line and add the port number you desire.  Stop and restart the OpenSSH services.  Make sure the port you chose is open in the windows firewall.

The elements listed below provide Windows-specific configuration possible through entries in sshd_config. There are other configuration settings possible in that are not listed here, as they are covered in detail in the online Win32 OpenSSH documentation.

AllowGroups, AllowUsers, DenyGroups, DenyUsers

Controlling which users and groups can connect to the server is done using the AllowGroups, AllowUsers, DenyGroups and DenyUsers directives. The allow/deny directives are processed in the following order: DenyUsers, AllowUsers, DenyGroups, and finally AllowGroups. All account names must be specified in lower case. See PATTERNS in ssh_config for more information on patterns for wildcards.

When configuring user/group based rules with a domain user or group, use the following format: user?domain*. Windows allows multiple of formats for specifying domain principals, but many conflict with standard Linux patterns. For that reason, * is added to cover FQDNs. Also, this approach uses "?", instead of @, to avoid conflicts with the username@host format.

Work group users/groups and internet-connected accounts are always resolved to their local account name (no domain part, similar to standard Unix names). Domain users and groups are strictly resolved to NameSamCompatible format - domain_short_name\user_name. All user/group based configuration rules need to adhere to this format.

Examples for domain users and groups

 
DenyUsers contoso\This email address is being protected from spambots. You need JavaScript enabled to view it. : blocks contoso\admin from 192.168.2.23
DenyUsers contoso\* : blocks all users from contoso domain
AllowGroups contoso\sshusers : only allow users from contoso\sshusers group

Examples for local users and groups

 
AllowUsers This email address is being protected from spambots. You need JavaScript enabled to view it.
AllowGroups sshusers

AuthenticationMethods

For Windows OpenSSH, the only available authentication methods are "password" and "publickey".

AuthorizedKeysFile

The default is “.ssh/authorized_keys .ssh/authorized_keys2”. If the path is not absolute, it is taken relative to user's home directory (or profile image path). Ex. c:\users\user.

ChrootDirectory (Support added in v7.7.0.0)

This directive is only supported with sftp sessions. A remote session into cmd.exe wouldn't honor this. To setup a sftp-only chroot server, set ForceCommand to internal-sftp. You may also set up scp with chroot, by implementing a custom shell that would only allow scp and sftp.

HostKey

The defaults are %programdata%/ssh/ssh_host_ecdsa_key, %programdata%/ssh/ssh_host_ed25519_key and %programdata%/ssh/ssh_host_rsa_key. If the defaults are not present, sshd automatically generates these on a service start.

Match

Note that pattern rules in this section. User and group names should be in lower case.

PermitRootLogin

Not applicable in Windows. To prevent administrator login, use Administrators with DenyGroups directive.

SyslogFacility

If you need file based logging, use LOCAL0. Logs are generated under %programdata%\ssh\logs. Any other value, including the default value AUTH directs logging to ETW. For more info see Logging Facilities in Windows.

Not supported

The following configuration options are not available in the OpenSSH version that ships in Windows Server 2019 and Windows 10 1809:

  • AcceptEnv
  • AllowStreamLocalForwarding
  • AuthorizedKeysCommand
  • AuthorizedKeysCommandUser
  • AuthorizedPrincipalsCommand
  • AuthorizedPrincipalsCommandUser
  • Compression
  • ExposeAuthInfo
  • GSSAPIAuthentication
  • GSSAPICleanupCredentials
  • GSSAPIStrictAcceptorCheck
  • HostbasedAcceptedKeyTypes
  • HostbasedAuthentication
  • HostbasedUsesNameFromPacketOnly
  • IgnoreRhosts
  • IgnoreUserKnownHosts
  • KbdInteractiveAuthentication
  • KerberosAuthentication
  • KerberosGetAFSToken
  • KerberosOrLocalPasswd
  • KerberosTicketCleanup
  • PermitTunnel
  • PermitUserEnvironment
  • PermitUserRC
  • PidFile
  • PrintLastLog
  • RDomain
  • StreamLocalBindMask
  • StreamLocalBindUnlink
  • StrictModes
  • X11DisplayOffset
  • X11Forwarding
  • X11UseLocalhost
  • XAuthLocation