How to generate a Public/Private key pair using PuTTY

1. Prerequisites

Install PuTTY on a Windows device. (Follow my guide here.)

 2. Start PuTTYgen

Start PuTTYgen (this will have been installed as part of the PuTTY install)

 3. Choose the type of key to generate

The choice here is between RSA and EdDSA, the trade-off is between performance and compatibility. RSA is universally supported among SSH clients while EdDSA performs much faster and provides the same level of security with significantly smaller keys. (For a full discussion see here.) ECDSA and DSA are both now considered insecure so do not use these.
EdDSA is compatible with Raspberry Pi OS and TrueNAS Scale so is a good choice.
 

4. Generate the key

Click ‹Generate› and then move the mouse pointer within the area below the progress bar. This introduces some randomness.
This has generated the public key we will use later. In this case:

ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC7OlzesPfehPyD87m0uGElWk13BPpiTAg0ydLHchkNO eddsa-key-20240401

Note there are no carriage returns in the text, only spaces.

5. Save the Keys

It seems intuitive to click <Save public key> to save a text file containing the public key but note this will not save the key in a format that can be imported to Authorized_keys. Copy the text from the Key box and save and use this.

Now click <Save private key> to save a copy of the private key. At this point you can also enter a Key passphrase this will increase the level of security but will have to be entered every time you log in.

If you have access to the console of the device you wish to enable eccess with keys the easiest method is to execute the following comands:

mkdir -p ~/.ssh
The next command will write the public key to the file authorized_keys in the hidden folder .ssh you just created.
echo “put your key here” >> ~/.ssh/authorized_keys
So for the above key it will look like this:
echo ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIC7OlzesPfehPyD87m0uGElWk13BPpiTAg0ydLHchkNO eddsa-key-20240401 >> ~/.ssh/authorized_keys

Now lets secure the directory and file so that only the used has access to the files. First remove group and other rights to .ssh recursivley.

chmod -R go= ~/.ssh

The owner of the directory and files withingn it should already be set but just to be sure replace owner in the following with the user you are logged in as:

chown -R owner:owner ~/.ssh

Leave a Comment

Scroll to Top