SSH: How to generate keys and connect to your account with PuTTY (Windows)
Note: You do NOT need to generate/use keys to access your Site5 account via SSH.
This tutorial will show you how to generate a public/private SSH key pair on a Windows operating system using PuttyGen (PuTTY Key Generator) and then install that on your Site5 account so you can use SSH keys for authenticating.
1. Download the PuTTY installer here.
2. After the files finish downloading, launch the installer and follow the on-screen instructions to install the PuTTY software. The default install location is fine, but I would recommend selecting the following options under the “Select Additional Tasks” screen:
* Create a desktop icon for PuTTY
* Create a Quick Launch icon for PuTTY (current user only)
* Associate .PPK files (PuTTY Private Key) with Pageant and PuTTYgen
3. Once the install is finished, launch PuTTYgen (which can be found in your Start Menu under “PuTTY”)
4. When PuTTYGen launches, you can keep all of the default settings, so you shouldn’t need to change anything (listed below)
* Type of key to generate: SSH-2 RSA
* Number of bits in a generated key: 1024
5. Now, click on the “Generate” button to create your key pair. You will need to move your mouse around within that blank space during that process.
6. Once the generator is complete, you will see a window with your new public key and key fingerprint.
7. Next, feel free to change the “Key comment” to anything you would like. I usually indicate the workstation name in the comment so I know where it came from. Something like “my-workstation-home.”
8. You then need to fill in the “Key passphrase” and the “Confirm passphrase” fields. These are important, make sure you set a passphrase! It should be a secure passphrase and one that is not easily guessable nor should it be used anywhere else.
9. You now need to select the contents of the public key in that large text field and copy the entire contents (control + C) into your clipboard. Do not quit PuTTYGen. Your public key will look similar to the below:
ssh-rsa AAAAB3NzaC1yc2EAAAABJQAAAIEAhCdDMhGHdaw1uj9MH2xCB4jktwIgm4Al7S8rxvovMJBAuFKkMDd0vW5gpurUAB0PEPkxh6QFoBNazvio7Q03f90tSP9qpJMGwZid9hJEElplW8p43D3DdxXykLays2M8V2viYGLbiXvAbOECzwD4IaviOpylX0PaFznSR4ssXd0= my-workstation-home
Now, open up Notepad and paste the contents into a new file (control + V). Save the file somewhere you will remember — you can save it as a txt file (publickey.txt).
The public key is what will be put on your Site5 account later.
10. Go back to PuttyGen and click on the “Save private key” button on the main window under the “Save the generated key” section. You can call that file “privatekey” or “privatekey.ppk” — make sure to save it somewhere you will be able to find.
Remember: the private key remains private and should never be given to anyone. It does not go on your Site5 account; it stays on your workstation. Keep this file safe or else you will need to re-do everything if the private key is ever lost.
11. You should now have a public and private key file saved on your workstation. You can quit out of PuTTYGen now.
12. The next step is to login to your Site5 account via SSH so you can install your public key.
13. Launch PuTTY (found under the “PuTTY” section in your Start Menu). In the “Category” section on the left, scroll down and under Connection > SSH, select the “Auth” option. Where it says “Private key file for authentication:” click on the “Browse” button and find the private key you generated previously and click the “Open” button to load it. The text field should now be filled in with the path to your private key.
14. Next, in the “Category” section, select the “Session” option towards the top of that list of options. Fill in the “Host Name” field with your account hostname (your account domain or IP address will also work).
Tip: To save this profile for later so you don’t need to do this each time you connect, type a name for this session in the “Saved Sessions” text field on the lower half of that screen. Then, click on the “Save” button to the right and the session will now be saved for later (it will show up where “Default Settings” is showing). Next time you connect to the server, you would simply select the session you created and then click on the “Load” button, and then select the “Open” button at the bottom to load that saved session.
15. Click the “Open” button and then you will be prompted for your Site5 account username and then the password. Enter those and then you will be logged in via SSH.
16. Type the following command at the prompt (and press the enter key on your keyboard when done):
mkdir ~/.ssh; touch ~/.ssh/authorized_keys; chmod 700 ~/.ssh
That will create a new SSH directory and a new blank file where we will be putting our public key and any additional public keys we want to have access to our account.
17. Next, open up the “authorized_keys” file in your favorite command line text editor (vi/nano/emacs). I will use nano here:
Note: Once you have made your changes, you can exit nano by pressing “Ctrl+X”, then press “Y”, and finally “enter” to confirm the overwrite/filename.
You now need to go to your workstation and find where you saved the public key you generated earlier in PuTTYGen (make sure you get the public key, not the private key!). Copy and paste the contents of the public key into the “authorized_keys” file on your Site5 server. It should paste as a single line, which is fine. Save the file and exit PuTTY.
18. Now, re-open PuTTY and make a new connection to your Site5 account like you did before (make sure to load your saved session or follow steps 13 to 15 again). You will be prompted for your login name, but this time you will not be prompted for your account password but instead will be prompted for your SSH key passphrase. The output should look something like this:
Authenticating with public key "my-workstation-home" Passphrase for key "my-workstation-home":
After you enter your passphrase and hit Enter, you should be logged in to your account via SSH.