SSH Setup for a Newbie

April 30, 2014 1.9k views
The workflow for setting up an SSH key is not totally clear for a newbie. I followed https://cloud.digitalocean.com/ssh_keys and created my key pair, but adding the public key to Digital Ocean is a little confusing. I am not able to copy the contents of the public key from the online console (copy/paste not available), and I am not sure what adding the key does. Can anyone explain this step-by-step without a lot of code. I looked at this and it also confused me: https://www.digitalocean.com/community/articles/how-to-set-up-ssh-keys--2 Note that I am trying to add SSH to an existing droplet. I have already created the key pair.
2 Answers
You should be a able to simply add your public key you to the authorized_keys file in your home directory /home/username/.ssh/authorized_keys file on your cloud server. You can either scp the file up to your cloud and add it it /home/username/.ssh/authorized_keys or even easier just copy the text of it an paste it into your /home/username/.ssh/authorized_keys (using vi or nano editor) on your cloud server. The main thing you have to remember is that your the .ssh folder and authorized_keys folder on the cloud server cannot be readable by anyone but your user or it will not work. You should set the permissions for /home/username/.ssh and authorized_keys to 700. Once this is done you should be able to ssh in without a password. If it doesn't work try ssh username@host -vvv to get more information on the exact error and post here for more help.
Adding a SSH key allows you to access the droplet without having to use a password. It is also more secure as you can then disable password authentication all together. That way only the key can be used to access it, and someone won't be able to use brute force attacks to try to login to your server.

It sounds like you are generating the key on the droplet itself. What you actually need to do is create the key on your local computer, not the remote server. You then copy the public key to the server while the private key stays on you local computer.

What OS are you using locally? If you're using Windows, you might want to look into using PuTTY:

https://www.digitalocean.com/community/articles/how-to-use-ssh-keys-with-putty-on-digitalocean-droplets-windows-users
by Justin Ellingwood
PuTTY is a Windows program used to establish SSH sessions with Linux servers. In this guide, we'll demonstrate how to use PuTTY to create SSH key pairs to use within the DigitalOcean interface. You can then easily create servers that you can log into without a password.
Have another answer? Share your knowledge.