Question

How exactly do I add a key to my DigitalOcean Droplet??

I changed my public and private keys on Terminal (I’m using Mac OS) many times. So when I “ssh” into the IP address given to me by my Droplet (the IP address is 107.170.60.7), I get the error of Permission denied (publickey). so I know it has to do with me changing the public/private key. So now I need to add that changed public key on my Terminal to my Droplet on DigitalOcean. There were two things suggested by the DigitalOcean community which I’ve tried:

  1. The tutorial on here - but this is for Windows users, not Mac. It’s suggests using a “Search and Replace” and checking certain functionalities. But Macs don’t have this so I can’t even use it: http://geektnt.com/how-to-add-ssh-key-to-existing-digitalocean-droplet.html

  2. A user kept suggesting to someone else that the problem is resolved by visiting this page: https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2 I read into it and it has everything to do with setting up a SSH key, which I already know, and NOTHING to do with how to ADD an ssh key to an existing Droplet.

I really just need to know how to add my changed ssh key to my Droplet. I would really appreciate the help if anybody knows.


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.

Hello, all

You can follow our tutorials on how to add your ssh-keys:

How to Upload an SSH Public Key to an Existing Droplet How-to Add SSH Keys to New or Existing Droplets

If you’re using a SSH-client the following command with upload the keys for you and you’ll just need to enter your username password:

cat ~/.ssh/id_rsa.pub | \
ssh username@203.0.113.0 "mkdir -p ~/.ssh && cat >> ~/.ssh/authorized_keys"

Hope that this helps! Regards, Alex

@confused5000

If you deployed the Droplet with an SSH Key, a root password is never set, thus you won’t be able to login using console, or login as root using a password.

That’s why I mentioned that you’re effectively locked out since you overwrote the older key.

@confused5000

To SSH in with a key, you have to pass the -i flag and define the full path. So if your key name was:

confused

On MacOS, you’d use:

ssh root@107.170.60.7 -i ~/.ssh/confused

That being said, if you created a Droplet with one key and then overwrote it, you’ve effectively locked yourself out. The only way to get around this would be if you set a password for root, then you could try to login without it, but seeing as you’re getting:

Permission denied (publickey).

… when trying to login with ssh root@107.170.60.7, that tells me that you don’t / didn’t.