SSH error - Permission denied (public key).

I followed this to try to add authorized keys to my droplet. I ended up loosing permissions in my starting machine and not being able to log in from the second machine either.

I could not type ‘~’ in the web console, so i am not able to authorize more keys either.

What can i do to overcome the: “Permission denied (public key).” error?

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.


When logged in as root, /root/.ssh is equal to ~/.ssh, so if for one reason or another, you’re unable to use ~, then /root/.ssh will work as a direct path.

In regards to /root/.ssh/authorized_keys, these are the public keys for the root user that are allowed to login. So if you’re attempting to login to SSH using a command such as:

ssh root@DROPLET_IP -i /path/to/private_key

… then private_key needs to be associated with one of the public keys in authorized_keys on your Droplet, else authentication will fail.

Not sure if this is your problem, but it was mine! I didn’t realise that just because the root user had authorized_keys, doens’t mean all the other users created do. I.e. if you create a VPS and Digital Ocean automatically adds SSH keys, these only go to the root user, so you have to mkdir .ssh for your new user and copy the SSH keys there and make sure the permissions correct.

Did you check /var/log/auth.log?