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.

KFSys
Site Moderator
Site Moderator badge
May 31, 2024
Pinned Answer

Since the last post on this topic there have been new Docs.

As such for anyone stumbling upon this, please check this docs page and read upon the process:

https://docs.digitalocean.com/products/droplets/how-to/add-ssh-keys/

@confused5000

To add an SSH Key to your Droplet, you’ll need to be able to access it. Do you still have the old key that you were using? If so, SSH in to your Droplet using the old key and add your new public keys to:

~/.ssh/authorized_keys

The format is one key per line. You can remove the old key from this file.

If you don’t have the old key that you were using, you may very well be locked out as console access to the Droplet is limited to password-based authentication.

@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.

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.