Verified and TestedÂ 2/8/15
This guide will show you how to generate and use SSH keys (public and private) using PuTTYgen and PuTTY for Linux servers.
In This Article
How to Generate and Use an SSH Key
First things first. We must generate our public and private keys using PuTTYgen. PuTTYgen and PuTTY can be downloaded here: http://www.chiark.greenend.org.uk/~sgtatham/putty/download.html
Once they have been downloaded to a proper directory, open PuTTYgen first. Click on â€œGenerateâ€ to begin the key generation process. It will ask you to move your mouse around over the program window to help generate â€œrandomâ€ data.
When the key is generated, the window will look like the picture below.
Most of the information presented here is superfluous except in special instances. All you will want to do is update the â€œKey commentâ€ box with a better friendly name for the key. Once you have done that, select all of the text in the â€œKeyâ€ box and paste it into Notepad or Notepad++ (preferred). Save that text file somewhere safe. You will also need to click â€œSave private keyâ€ on this window. Name it something useful and place it somewhere secure as well.
To use this key with a PuTTY connection, simply select the â€œAuthâ€ menu on the left side of the program. This can be found under Connection -> SSH -> Auth. In this menu, there is a box titled â€œPrivate key file for authentication.â€ Click browse and find the .ppk file that you saved in the previous step.
At this point, if you name and save your connection in the â€œSessionâ€ category, you wonâ€™t ever have to follow this process again for that server/IP. Otherwise, you would need to choose your key each time you connect.
Creating a New Server with this SSH Key for Linux Servers
Creating a cloud server that uses an SSH key is simple. You will first need to setup your key in the cloud portal.
Click on â€œSSH Keysâ€ on the left side under â€œManage Servers.â€
From there, click â€œAdd SSH Key.â€
When the window pops up, simply name your key, and paste the public key text (that you saved to a notepad file in a previous step) into the large box.
Click â€œAdd Key.â€ If there were no issues with the key (inappropriate line breaks, errors, etc) it will save to the portal and be accessible for new servers.
To create a server that utilizes this key for root login, simply follow the â€œcreate serverâ€ steps found here.
-When choosing your server size and OS, you will see an option at the bottom that says â€œPick SSH Key.â€ You will see the key we just created in that list. When the server comes online, simply use the previous PuTTY steps to connect to the server using that public key. The username will always be root when using our public key system.
Adding the Public SSH Key to an Existing Server
The steps for enabling public/private key login on a standard server that was not provisioned with a key originally is quite simple as well
Simply use PuTTY to log into the server as usual using the root account and password. You may already want to save a PuTTY profile with your key, even though the server will reject it until it is configured.
For all Linux-based operating systems, you only need to create rootâ€™s .ssh directory, and paste the public key into a file named â€œauthorized_keysâ€
From here, you can either use a text editing program to paste the key in (vi/vim/nano, etc), or you can use echo. The echo command would look something like this:
At this point, you can log out of the server and log in using the previously stated method to open a PuTTY session with a private key attached. Upon entering the username â€œrootâ€, the server should allow you to login without entering a password. If successful, you should see a message that states â€œAuthenticating with public key.â€ The screenshot below has an example:
Done! At this point, if you plan to access the server often, you will definitely want to save a profile. You can also setup a username to auto-login with under Data -> â€œAuto-login username.â€ Simply type root into that box and save it along with the private key and IP address to a PuTTY profile, and you can have instant passwordless login access to your server!