See Stacksync in action with a solution architect. Book a demo ↗

Windows Server 2022 Jumpbox

This guide is to connect to a Windows server through SSH (13 min setup required).

I. Install OpenSHH

  1. On the Windows server, open the Settings and go to Apps.

    Windows Settings home with the "Apps" category highlighted.
  2. Go to Optional Features.

    Windows Settings "Apps & features" page with the "Optional features" link highlighted, used to install OpenSSH Server.
  3. Install OpenSSH Server.

    Windows "Add an optional feature" dialog with "OpenSSH Server" searched and listed, ready to install.

II. Switch On OpenSSH Server

  1. Open Computer Management application.

  2. Go into Services and Applications > Services.

  3. Click on OpenSSH Server.

  4. Set Startup type to Automatic and click on Start.

    OpenSSH SSH Server Properties in Computer Management with Startup type set to "Automatic" and the "Start" button highlighted.
  5. Keep this window open, we will have to come back to it soon.

III. Set Up OpenSSH Server

  1. Open a terminal with Administrator role

  2. Open the OpenSSH Server config file by running:
    notepad "C:\ProgramData\ssh\sshd_config"

  3. Uncomment PubkeyAuthentication.

    sshd_config open in Notepad with the line "PubkeyAuthentication yes" uncommented and highlighted.
  4. Uncomment PasswordAuthentication and set it to no.

    sshd_config with "PasswordAuthentication no" uncommented and highlighted to disable password logins over SSH.
  5. Comment out the 2 last lines of the file (Match Group Administrator).

    sshd_config in Notepad with the last "Match Group administrators" and AuthorizedKeysFile lines commented out and highlighted.
  6. Save and quit the file. If you cannot save, you most certainly did not open the terminal as an Administrator, you need to open a new terminal with Administrator rights and redo the configuration changes done in this section.

  7. In the Computer Management window, restart the OpenSSH Server.

    Computer Management Services list with OpenSSH SSH Server selected and the "Restart the service" link highlighted.

IV. Upload the Public SSH key of the server you want to connect from

  1. Go to Users, then open the folder associated with the Windows user you want to connect to.

  2. Create a new folder .ssh

    Windows File Explorer showing the user folder under C:\Users with a newly created ".ssh" folder.
  3. In this newly created folder, create an empty text file authorized_keys

  4. By default, text files are created with a .txt extension, we need to remove it.

    1. Click View in the header bar.

    2. Tick the checkbox File name extensions

      File Explorer View ribbon with "File name extensions" and "Hidden items" checkboxes ticked and highlighted.
    3. The .txt file extension should now be visible.

      File Explorer .ssh folder showing "authorized_keys.txt" with the ".txt" extension now visible and highlighted.
    4. Rename the file to remove the file extension. You can safely ignore the warning.

      File Explorer .ssh folder showing the renamed "authorized_keys" file with no extension, type "File".
  5. Add the PUBLIC SSH key of the server that you want to grant access to this Windows server we are currently configuring. The public key is of the form: ssh-<encryption_algorithm> <key> .

V. Test

Try connecting through SSH to the Windows instance we just set up:

ssh -i <path_to_ssh_private_key_of_client> <ssh_user>@<windows_server_public_ip>

where:

  • -i <path_to_ssh_private_key_of_client>: Specifies the private key file for authentication of the client, not of the Windows machine. The private key file should be readable and writable only by its owner and should be of the form:
-----BEGIN PRIVATE KEY-----
          ...
          ...
-----END PRIVATE KEY-----
  • ssh_user : the Windows User for which you uploaded the client public key. In the screenshots above it is 'alexis'.
  • <windows_server_public_ip>: The public IP address of the Windows server.

You should now have been able to access this Windows server through SSH 🎉
If you are blocked or have any question, feel free to reach out to us at hello@stacksync.com we're happy to help!

Troubleshooting of common errors

Permissions 0644 for <path_to_ssh_private_key_of_client> are too open. It is required that your private key files are NOT accessible by others. This private key will be ignored.

-> You need to let only the owner of the file read and write to that file.
Run this: chmod 600 <path_to_ssh_private_key_of_client>

'export' is not recognized as an internal or external command, operable program or batch file.
-> This is an error due to your client terminal, try using the default terminal of the client machine. This error typically happens when using Warp as terminal.

Permission denied (publickey,keyboard-interactive).

-> You most certainly missed one of the above steps of that tutorial, or the public SSH key uploaded on the Windows server does not correspond to the private SSH key of the client.

timeout error

-> The Windows server is not listening to the client IP and the port you are trying to connect to (SSH default port is 22). Make sure you whitelisted the client IP.

On this page