# Windows Server 2022 Jumpbox

### I.  Install OpenSHH

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

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FEdzA5pVnD8T2Ya72WxUk%2Fimage.png?alt=media&#x26;token=4e8b3fbc-254d-4fe7-9cec-21bf2d3c76e6" alt=""><figcaption></figcaption></figure>
2. Go to Optional Features.

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FmXcFKEa5xf2hYPev7vDZ%2Fimage.png?alt=media&#x26;token=d5c6aec4-7afd-4a23-9193-149291379430" alt=""><figcaption></figcaption></figure>
3. Install OpenSSH Server.

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FVykRu2rMJR33beLJ7DJo%2Fimage.png?alt=media&#x26;token=53d6661a-80f8-4a3c-a1a8-22d2460d0504" alt=""><figcaption></figcaption></figure>

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

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FmoGI3fOD08R1oFm9Ug8A%2Fimage.png?alt=media&#x26;token=04b401dd-4c62-4a05-af23-764e500c583e" alt=""><figcaption></figcaption></figure>
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:\
   &#x20;`notepad "C:\ProgramData\ssh\sshd_config"`
3. Uncomment PubkeyAuthentication.

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2Fw53vMu6TDZslNe1msSpQ%2Fimage.png?alt=media&#x26;token=74b65fc0-36dc-4edf-91cc-981e7cab8d8a" alt=""><figcaption></figcaption></figure>
4. Uncomment PasswordAuthentication and set it to no.

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2Ft31L3xVV4Uyw2B2YjXwU%2Fimage.png?alt=media&#x26;token=55b65eab-0ef2-4d70-b624-f26d563f38d9" alt=""><figcaption></figcaption></figure>
5. Comment out the 2 last lines of the file (Match Group Administrator).

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FCjxO5QXw1VhS87Qxrp8u%2Fimage.png?alt=media&#x26;token=cdc45cf8-5cef-4d0b-97cb-71123dd86d3d" alt=""><figcaption></figcaption></figure>
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.

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2F9SukvQnW2IIqd9BWNiYi%2Fimage.png?alt=media&#x26;token=639808ac-e110-4b7d-94dc-cba146a1b249" alt=""><figcaption></figcaption></figure>

### 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`

   <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FMaQSy3Nzi5WSlj7qYtrC%2Fimage.png?alt=media&#x26;token=ed4e29b1-4d1c-4ba6-afec-51ffc1257c0d" alt=""><figcaption></figcaption></figure>
3. In this newly created folder, create an empty text file `authorized_keys`&#x20;
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`&#x20;

      <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FSX71Eo6r52m9XJoRJLdP%2Fimage.png?alt=media&#x26;token=acd5dac2-7ae6-468a-907d-d42cd59e9656" alt=""><figcaption></figcaption></figure>
   3. The `.txt` file extension should now be visible.

      <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FAVwtEvJVIhWuKGkzMf7l%2Fimage.png?alt=media&#x26;token=d3dad428-7d34-42b3-b28e-ea6a4ab5f707" alt=""><figcaption></figcaption></figure>
   4. Rename the file to remove the file extension. You can safely ignore the warning.

      <figure><img src="https://2867423571-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfJjIdV9cuW6K8asJjTPJ%2Fuploads%2FOCz3u4PNEIVubLKVpNKn%2Fimage.png?alt=media&#x26;token=da4d9eeb-9f07-4681-8ec6-44d1bf881e8d" alt=""><figcaption></figcaption></figure>
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:

<pre><code><strong>ssh -i &#x3C;path_to_ssh_private_key_of_client> &#x3C;ssh_user>@&#x3C;windows_server_public_ip>
</strong></code></pre>

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   :tada:\
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

{% hint style="info" %}
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.\
&#x20;    Run this: `chmod 600 <path_to_ssh_private_key_of_client>`
{% endhint %}

{% hint style="info" %}
'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.
{% endhint %}

{% hint style="info" %}
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.
{% endhint %}

{% hint style="info" %}
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.
{% endhint %}
