Question

How do i add an ssh key to an existing droplet?

Hello,

I have been trying to add a public key on a pre-existing droplet and I am not able to connect although I have tried to paste it on the original SSH KEY, and on a new key. I have followed this https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets tutorial, but it is not really showing it well on how i can get into a preconfigured drop-let.

Thank you

Show comments

Submit an answer

This textbox defaults to using Markdown to format your answer.

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

Sign In or Sign Up to Answer

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.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.

You can add an ssh key to an existing droplet by appending the public key (ssh-rsa ...) to /home/user/.ssh/authorized_keys or /root/.ssh/authorized_keys.

If you’re on Linux, you can run the following command to do that automatically:

ssh-copy-id user@123.45.56.78

On OSX, you can run this command instead:

cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

I got it to work by adding the ssh key to both /root/.ssh/authorized_keys and /root/.ssh known_hosts then restarting the droplet

The following have worked for me:

  1. Create GitHub repo and put your key in it
  2. Clone the repo using console
  3. Run cat /path/to/cloned/github/project/key | cat >> ~/.ssh/authorized_keys

NB key is a file containing the id_rsa.pub value