Creating and using SSH keys
As the third video in this series on making SSH access to a CentOS Linux server more secure, this tutorial
will show you:
How to Create and Use SSH Keys with PuTTY
With this video tutorial, you will learn how to use SSH keys to connect to a CentOS server from a Windows PC,
using the PuTTY SSH client and PuTTYgen utilities. You can download PuTTY and the PuTTYgen utilities from
the URL displayed in this video and from the link in the text below.
- To generate a set of RSA keys, launch the PuTTYgen utility. RSA is a cryptosystem for public-key
encryption.
- On the PuTTYgen Key Generator screen, make sure the "SSH-2 RSA" option is selected, then click the
“Generate” button, and move your mouse around the area, as instructed on the screen. This will generate
some randomness and will take a few seconds to complete, as seen in the progress bar.
- Once complete, you will see a generated public/private key pair.
In the "Key comment:" field you can enter any comment you like to help you identify the generated key
pair.
Click the "Save public key," choose location to save it, name the file as you like and click "Save."
- On the PuTTY Key Generator screen, click the "Save private key"
- On the "PuTTYgen Warning" window, click "Yes."
- Choose the location to save the file, name the file as you like, and click "Save."
- The location of the files can be the same, but ensure that only you have access to it and that you do
not lose the keys.
Next, right click in the text field beneath, "Public key for pasting into OpenSSH authorized_keys file:"
and choose "Select All."
- Right click again and choose "Copy."
- Now, you will save your copied public key log to the CentOS server.
Open the terminal and at the command prompt type
mkdir ~/.ssh
and press Enter.
- Then, type
chmod 0700 ~/.ssh
and Enter.
- Next, type
touch ~/.ssh/authorized_keys
and Enter.
- Then, type
chmod 0644 ~./ssh/authorized_keys
and Enter.
- Now you will edit the authorized keys system file. At the prompt, type
sudo vi ~./ssh/authorized_keys
and press Enter to execute the editor.
If prompted to enter sudo password type your user's password and press Enter.
- On the editor screen, press the Insert. key and right click your mouse to paste the copied
public key.
- Press the Esc. key, type :w and press Enter to save the file.
- Type :q and press Enter to exit the editor.
- To configure the PuTTY profile in your Windows PC, open the PuTTY utility.
In the "Host Name (or IP address)" field enter your server's IP
- In the "Port" field, enter the custom port configured during the “How to Change the Default SSH Port”
tutorial.
- Make sure the "Connection type:" is SSH.
In the "Category:" section on the left pane under “Connection,” choose "Data."
In the "Auto-login username" field, enter the user name you created in the How to Create a New User
tutorial.
Go to the "Category:" section in the left pane and under “Connection,” expand "SSH."
Under "SSH," highlight "Auth" to access the Options controlling SSH authentication screen.
- In the "Authentication parameters" section click the "Browse..." button and browse to the location where
your private key file is stored.
Choose it and click "Open."
- In the "Category:" section in the left pane, highlight "Session," and enter a chosen name for the
profile in the "Saved Sessions" field and click “Save.”
- Choose the newly saved profile, and click "Open" to connect to your CentOS server using the SSH key
pair.
Thanks for joining us and return often to see new tutorials from Superb.net.