Note: you do NOT need to generate/use keys to access your account via SSH.
This tutorial will show you how to generate a public/private SSH key pair on a Windows operation system using PuTTYgen (PuTTY Key Generator) and then install it on your HostNine account. This allows you to use SSH keys for authenticating!
To get started:
- Download the PuTTY installer
- Once the download is all finished, go ahead and launch the installer and follow the on-screen instructions to install PuTTY
- The default location is fine but we recommend selecting the following options when you get to the Select Additional Tasks screen:
- Create a desktop icon for PuTTY
- Create a Quick Launch icon for PuTTY (current user)
- Associate .PPK rules (PuTTY Private Key) with Pageant and PuTTYgen
- Launch PuTTYGen (in your Start Menu under ‘PuTTY’)
- When PuTTYGen launches keep all of the default settings (listed below):
- Type of key to generate: SSH-2 RSA
- Number of bits in a generated key: 2048
- Click the Generate button to create your key pair (move your mouse around within the blank space during the process)
Once the generator is complete, you will see a window with your new public key and key fingerprint.
- Change the ‘Key comment’ to anything you would like (maybe the workstation name, for easy identification: ‘my-workstation-home’)
- Fill in the Key passphrase and the Confirm passphrase text fields
Note: these are important, make sure you set a passphrase! Make sure it’s a secure passphrase and isn’t easily guessable or is used elsewhere.
- Select and copy (CTRL + C) the contents of the public key located 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 AAAAB3NzaC1yc2EAAAABJQAAAQEAgIXR9GaGgkaX99NDEeGZqELW9xRkwJc9+BH679FNL//BKSF8k/zGRuWP4ab9Zy0eSlqOVMS5PUeHIhiaddym6MHaBRf9GXxvMOUdVsNh7Eff1S9y3NVcDGhvKaXOmhNHZEWNh0sED+q8oX6lmyzCF92xn+XeCbxrGRetoGSzlyjtl0BDudHME3CyX4VpSkk2wJ8X/IPHFiqvaTyuVIss0n9xrsbN1RmrwrmmSQ+DKA5VBbbpBqI6y87RBW2x1W6IOaaM5izSa5EBjS6ixwjf2Qs9Aj2O93YhQxjUMOeFmpdSI1ZP68pnIcJf9iOv/7zTWy8GwwctCJjCbi94odY3iQ== my-worsktation-key
- Open Notepad (or similar text editor), paste (CTRL + V) the contents you just copied into your new text editor file and save it as a .txt file
The public key will be applied to your HostNine account later.
- Go back to PuttyGen and click the ‘Save private key’ button on the main window under the ‘Save the generated key’ section
Note: you can call that file ‘privatekey’ or ‘privatekey.ppk’ — make sure to save it somewhere you will be able to find it easily.
The private key stays private and should never be given to anyone. It does not go on your HostNine account; it stays on your workstation. Keep this file safe! If you lose your private key you’ll need to redo this entire process.
- Quit PuTTYGen
Now, we're gonna log in to your HostNine account via SSH so you can install your public key.
- Launch PuTTY
- 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 the Browse button
- 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.
- Click Session, in the Category section, and fill in the ‘Host Name’ field with your account hostname (your account domain or IP address will also work)
Tip! You can save this profile for later, to help eliminate some of the work, by typing a name for the session in the Saved Sessions text field. Then, click the Save button. The sessions will be saved and will show where Default Settings currently shows. When you connect to the server next time simply select the session you created and click the Load button. Click the Open button at the bottom to load up that saved session!
- Click the Open button and enter your HostNine account username and password when prompted
You’re logged into SSH!
- Type the following command at the prompt (and press Enter when you’re done):
mkdir ~/.ssh; touch ~/.ssh/authorized_keys; chmod 700 ~/.ssh
- That command will create a new SSH directory and a new blank file where you can put your public key and any additional public keys needed to access your account
Note: all keys need to be on separate lines in the file.
- Open the ‘authorized_keys’ file in your favorite command line text editor (vi/nano/emacs)
Note: for the sake of this example we are using nano.
- Once you have made the changes exit your text editor, making sure to confirm the overwrite/filename if necessary
- Go to your workstation and locate the public key you generated earlier in PuTTYGen (make sure you’re nabbing the public key, not the private key!)
- Copy and paste the contents of the public key into the ‘authorized_keys’ file on your HostNine server; it should paste as a single line
- Save the file and exist PuTTY
- Re-open PuTTY and make a new connection to your HostNine account like you did previously, and make sure to load your saved session like instructed
- Enter your login name and SSH key passphrase when prompted and then hit Enter
The output should look something like:
Authenticating with public key "my-workstation-home"
Passphrase for key "my-workstation-home":
You’re logged into your account via SSH!