Question

Add SSH key after creating a droplet

  • Posted May 14, 2014

Hi There,

I did not add the SSH key before creating the droplet. Now my server is all set and is about to go live. I cannot setup another one but really need to add an SSH key.

Is there any way I could do that. Also I cannot se any droplet resize option available, any ideas why is that? I’m currently running LAMP on Ubuntu 12. 512 MB droplet.

Thanks.

Subscribe
Share

What if you’re doing this from a Windows machine? Haha I kind of would hate to install Ubuntu locally, just to get my past this one hang up.

Because you didn’t use the backpack ( ` ) in your comment, it is missing the underscores and made the code italics

This is what is meant:

cat ~/.ssh/id_rsa.pub | ssh root@<YOUR_IP> 'cat - >> ~/.ssh/authorized_keys'

This thread is a little old, but you can just use git for windows to generate an ssh key from cmd. https://git-for-windows.github.io/

cat ~/.ssh/id_rsa.pub | ssh root@<YOUR_IP> ‘cat - >> ~/.ssh/authorized_keys’


Submit an answer
You can type!ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

To add a SSH key after the creation of the droplet, you need to add the contents of the public key to the file ~/.ssh/authorized_keys You can do that by running this on your local computer: <br> <br><pre> <br>cat ~/.ssh/id_rsa.pub | ssh root@your.ip.address “cat >> ~/.ssh/authorized_keys” <br></pre> <br> <br>You need to power down the droplet before you can resize it.

Exactly! I had to add an SSH key to an existing droplet but couldn’t log in via SSH because of “permission denied (publickey)” so all these instructions are not working if you disabled password login. I lost a lot of time trying to get access to my droplet from a new computer. The only solution was to get my old computer and log in from there with the old SSH key. The Digital Ocean console is completely non-functional. It just doesn’t work. If I paste in my SSH key it gets altered, upper-case letters become lower-case letters, the string is cut off in the middle etc. and it’s extremely slow and non-responsive. All in all a very frustrating experience!

These answers are all great, accept whenever I try to connect to my digital ocean server I get, ‘permission denied (publickey)’ when using any username set up including root and therefore I cannot add the key?

None of this works.

How about when you already have an SSH key used with other droplets but start a new droplet without using it; how do you later implement SSH logins using that key?

This snippet/command from https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets did not work

"In order to add additional keys to pre-existing droplets, you can paste in the keys using SSH:

cat ~/.ssh/id_rsa.pub | ssh root@[your.ip.address.here] “cat >> ~/.ssh/authorized_keys” "

Here is the working guide on how to add a SSH key to existing droplet (for Windows users) http://geektnt.com/how-to-add-ssh-key-to-existing-digitalocean-droplet.html

For anyone finding this via Google that found this answer: logging into your droplets via SSH on a Windows machine where you might be using a specialized client to generate your keys, the command asb uses in this comment thread doesn’t work, and there really aren’t any answers to tell you why.

Here’s an explanation. For a quick command-line copy and paste answer, scroll to the bottom of this comment. Breaking down the command:

cat ~/.ssh/id_rsa.pub

On a *NIX machine, this would output your local public SSH key.

|

The pipe character is standard Shell-speak for “piping” data into the stdin (input console) of a program or file handle. An easy way to remember it is the output of the command on the left will be received as input for the command on the right.

ssh root@your.ip.address "cat >> ~/.ssh/authorized_keys"

This is standard use of the SSH command, except the part in quotes actually encloses a command to send to the server you’re SSHing into.

What this adds up to mean is “output my local public key into the authorized_keys file on the server I’m SSHing into”. Which, on Windows, unless you use a platform like Cygwin for all of your SSH, means it wouldn’t work, because Windows isn’t a *NIX-style platform.

Solution for Windows users using native SSH clients: Paste the following into a root shell on your droplet:

echo "YOUR_SSH_PUBKEY_GOES_HERE" >> ~/.ssh/authorized_keys

Your SSH key should now be authorized on the droplet.

I didn’t see this in the answers below. But if you already have a public key that you want to reuse, you can just add it to ~/.ssh/authorized_keys file.