How to create SSH keys in Windows?

Key creation

To create a key in Windows, we will use PuTTYgen utility. It is installed as part of the standard PuTTY.msi package. No need for downloading PuTTYgen separately. Load PuTTY installer from putty.org and install the entire package.

Launch PuTTYgen. Go to the Start Menu "Start" --> "All programs" --> "PuTTYgen"

Putty gen start

To create a new key pair, select key type to generate from the bottom of the screen (using SSH-2 RSA featuring a key size of 2048 bits is suitable for most people; another good well-known alternative is ECDSA).

Then press "Generate" and start moving the cursor on the screen within the empty field. Putty uses mouse movements to generate random values. The exact way of mouse movement can not be predicted by an external attacker. You need to move the mouse for some time, depending on the size of your key. When you move it, the green progress indicator must move forward.

putty Key gen progress

Once the progress indicator is filled, the actual generation of the key will be calculated. Upon completion, public key must appear in the screen. Now you can set a passphrase for the key (you can omit it). You must save at least private key by pressing "Save private key".

copy-paste key

For OpenSSH servers, access to a user account is granted by adding a public key to file ~/.ssh /authorized_keys on the server.

Setting a key

To set a public key, connect to the server, edit the authorized_keys file with your favorite editor and cut and paste the output of the public key into the authorized_keys file. Save the file. Now the only we need is to add our private key to the ssh-agent of "Pageant" ("Start" --> "PuTTY" --> "Pageant"). 

Pageant is an application included in the distribution package of PuTTYThis software is used to store private keys in memory in a decoded form to be used when a request is received from a remote server. In order to add a previously created private key, you need to start Pageant, call it from the system tray with the right mouse button and select "Add key" in the appeared menu.

pageant add-key menu

After the key is selected, a password entry window may appear prompting for the password which was added when creating the key for enhancing security. Further, all downloaded keys are available in the list of keys (menu itemView Keys):

pageant Key list

Now let's log into PuTTY. 

Connection to Linux operated server via SSH

If you did everything correctly, you will see the message:

login as: root
Authenticating with public key "rsa-key-20171120" from agent

Done