This article will take you through generating RSA keys using PuTTYgen on Windows for secure SSH authentication with OpenSSH.
Contents |
One effective way of securing SSH access to your Cloud Server is to use a public/private key. This means that a 'public' key is placed on the server and the 'private' key is on our local workstation. This makes it impossible for someone to log in using just a password, provided you have setup SSH to deny password-based authentication (which you can learn how to do in this article about SSH).
In Windows we will use PuTTYgen to generate our public and private keys. You can download PuTTYgen from its official website (it might also have been installed with PuTTY or WinSCP). Launch the program then click the Generate button, as seen below. You will notice that it generates the keys for you. All you need to do now is save the public and private keys by clicking the buttons stating as such.

Open up your public key, copy it to the clipboard (ctrl+a, ctrl+c) and paste it at the very end of ~/.ssh/authorized_keys on your Cloud Server. If that file doesn't already exist, you will have to create it (nano ~/.ssh/authorized_keys).
To make use of your newly generated RSA key pair, you will need to tell PuTTY to use it when connecting to your Cloud Server. Do this by opening PuTTY and going to the "SSH" -> "Auth" section. Browse to where you saved the keys and load the private key as seen below:

Make PuTTY use the key every time you connect to your Cloud Server by saving this configuration. After loading your key as shown above, go back to "Session" and save your session:

Once you have saved your session, your key will be loaded automatically upon connecting to your Cloud Server.
Opting for a key-based authentication to your SSH server is beneficial in many ways. By eliminating the possibility of SSH brute-force attacks targeted towards your Cloud Server, the chances of it being compromised are decreased by an order of magnitude.
© 2011-2013 Rackspace US, Inc.
Except where otherwise noted, content on this site is licensed under a Creative Commons Attribution-NonCommercial-NoDerivs 3.0 Unported License

13 Comments
Comment - What about
Can you please provide few examples?
Re: plink
[http://the.earth.li/~sgtatham/putty/0.61/htmldoc/Chapter7.html#plink](http://the.earth.li/~sgtatham/putty/0.61/htmldoc/Chapter7.html#plink)
Basically you can use plink to make an ssh connection with a command like:
plink -ssh username@myserver.com
You can use a saved session name for the connection target, and that will use anything you've configured for that connection in PuTTY. That means you could make a session named "myserver" that has the protocol set to ssh and that sets the username for you. You can also add a key to that saved session so a script could use plink without needing to include a password. To use the session and then run the command "runscript.sh" on the server, you'd type:
plink mysession runscript.sh
I hope that helps. The documentation is definitely the best place to check for a more thorough explanation of what options you can use with plink.
This doesn't seem to work
Sorry...
Connection
re: Connection
You might search for a good Linux command-line primer to get you started. Putty acts as a terminal program, connecting you to a Linux server, and you use typed commands to navigate from there.
Server Refused Key
Here is exactly what I did:
- Generated the public/private key pair with PuTTYgen
- Saved the private key on my local machine
- Copy/pasted the public key into /home/username/.ssh/authorized_keys on my Cloud Server
- Configured my PuTTY session to use my local private key file when connecting to my server
- Attempted to connect via PuTTY with user "username" (as defined above)
- Received a message saying "Server refused our key"
What am I doing wrong?
re: Refused key
Basically, ssh is really sensitive about the key file so everything has to be just so. Most of the time I run into that error it's because of one of the issues I mentioned.
Ok, I generated a new public
Is there anything I need to change in the SSH config or something like that?
I did the:
chmod 600 ~/.ssh/authorized_keys
And I'm still getting the "Server refused our key" message... Must be some small stupid thing I'm doing wrong...
re: chmod
Putty - Server refused our key
Add new comment