SSH into Digital Ocean error: “Permission denied (publickey)”

This snippet was borne from a roadblock I encountered when following the official Digital Ocean tutorial for “How to Set Up SSH Keys“. When following those steps I got stuck trying to copy the public key from my local computer to the DO Droplet with the response “Permission denied (publickey)”. Here is how I fixed the problem:

For those who are trying to add a new key to an existing droplet – READ THIS!!!!

If you are getting the “Permission denied (publickey)” when trying to copy your public key to the server, you likely have password authentication disabled in your droplet.

How to fix this:
Log in to your DigitalOcean account and open the console for the drop you are trying to access. While inside the console do the following:
sudo vim /etc/ssh/sshd_config
Scroll down to the very bottom and look for the following directives:
UsePAM yes
IgnoreUserKnownHosts no
PasswordAuthentication no

If UsePAM is set to ‘yes’ and PasswordAuthentication is set to ‘no’ change those to the opposite. It should read the following:
UsePAM no
IgnoreUserKnownHosts no
PasswordAuthentication yes

Then press esc, type : (colon), and type wq and hit enter

This will quit vim editor.

Now type reload ssh

Now go back to your terminal or putty and pick up at the step where it has you copying your local rsa public key to the server. You should now be presented with a request for a password instead of public key denied. Type in your droplet password and hit enter. You should know be inside your server.

Now you can change those settings back from Putty or Terminal by typing the following:
sudo vim /etc/ssh/sshd_config

Change the directives back to what they were and press esc, type : (colon), and type wq and hit enter

reload ssh Again.

Now you can quit the session by typing exit and try to login with just ssh by typing:
ssh username@dropletIP.

Now you should be able to access your server via SSH with your newly created SSH key!

This was a PITA to figure out, but that is what got it all done for me.

The_Idiot

About Lindsay

Self made millionaire.. Oops I mean web developer.. who started out learning how to build websites with tables and dreamweaver, I now almost entirely focus on CMS-based development, usually WordPress. I love coding and designing and regularly switch between my left and right brains.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">