Step 4.4 How to Generate a Key Using PuTTY

Problem: How do you generate a key pair using PuTTY?

Action 4 4 1 Generating a public private key pair with PuTTY

PuTTY comes with the program PuTTYgen to generate public and private key pairs. To use PuTTYgen:

In the Parameters section are three options for the type of key to generate. SSHv1 only supports one type of key, so if you need to authenticate to a server that only supports SSHv1 make sure the radio button next to SSH1 (RSA) is selected.

If you will be connecting to a server that supports SSHv2, you have two choices for keys: SSH2 RSA and SSH2 DSA. The server you are connecting to may only allow one type of key, so you may have no choice as to what type of key you need to create. Click on the radio button next to the type of key you choose to create.

Action 4 4 2 Setting up public key authentication

Now that your public and private keys are created, you need to set up the remote server to accept our newly generated keys:

If the file does not exist, you can create it with your favorite editor. (In the rest of this example, we will refer to this file as the authorized_keys file, although the actual filename may differ depending on your version of SSH.)

If the authorized_keys file permissions are incorrect, change them with the chmod command, as shown below:

[sshuser@server.example.com]$ chmod 644 authorized_keys

Action 4 4 3 Using PuTTY to log in with public key authentication

Now we need to tell PuTTY to use public key authentication to log into the server:

Action 4 4 4 Use public key authentication from the command line PuTTY tools

We have seen that we can use public key authentication with PuTTY, the graphical SSH interface, but sometimes we may want to use public key authentication when using the PuTTY command line tools PSCP, PSFTP and Plink.

Each of these programs provides a “i command line option for specifying the path and filename of the file containing the private key. Whenever the “i option is specified for any of these tools, they will automatically try to authenticate using public key authentication.

The following example shows how to use PSCP to transfer files using public key authentication. The same procedure is used for PSFTP and Plink:

Action 4 4 5 Removing your public private keys

Since your public and private keys are stored locally in a file, removing them is as simple as deleting the file. Of course, this will only delete them on your local machine and not any servers where you may have copied your public key. To remove those, refer to Action 4.3.4.

Категории