Question

Cannot upload ssh key to my Droplet from Windows OS and keep getting "permission denied (publickey)" error

I have two computers, one OS Mac and one OS Windows. Using the Mac i managed to add the SSH public key and I can log into the droplet from the local machine terminal. On the one using windows, however, everytime I try to log in it throws the error “permission denied (publickey)”. I tried to follow the tutorials:

  1. https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/create-with-putty/
  2. https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/to-existing-droplet/ Still, I cannot get through it. For example, in the session https://www.digitalocean.com/docs/droplets/how-to/add-ssh-keys/to-existing-droplet/#manually it says to paste the key with nano editor but when I try to paste it, some characters of the key are changed (encrypted?) and I do not want to manually copy and paste the key inside the text editor. Also, I do not have in my local machine this file “cat ~/.ssh/id_rsa.pub”. Is it simply referring to the Putty key saved as private after the creation which I already added to the account (but not to the droplet)? Also, even from the droplet web console when I try to use the “ssh” command it throws the error “permission denied (publickey)” so I cannot really do anything. What am I doing wrong? Where can I find a working tutorial? Thanks in advance for the answers. Enrico.

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,

If the PasswordAuthentication is currently disabled you can try to enable it just temporary in order to access the droplet with the root password and upload your ssh-key. Once this is done you can again disable the PasswordAuthentication in order to keep the droplet secure.

Dropbox in case you don’t have any other server to us.

  1. Login to the console on the DigitalOcean website.
  2. Type sudo nano /etc/ssh/sshd_config
  3. Change PasswordAuthentication from “no” to “yes” and save the file
  4. Open a terminal on your computer and type ssh username@[hostname or IP address] or if on a Windows box use PuTTY for password login making sure authentication parameters aren’t pointing to a private key
  5. Login with password
  6. Type sudo nano ~/.ssh/authorized_keys
  7. Paste public key text here and save the file
  8. Type sudo nano /etc/ssh/sshd_config
  9. Change PasswordAuthentication from “yes” to “no” and save the file
  10. Log out and attempt to log back in (if using PuTTY make sure you set up auth parameters to point to your private key)

Hope that this helps! Regards, Alex

I think you managed to generate two keys, first one from you Mac and the second one from your Windows machine.

I would recommend to use the same private key (from your Mac) on both machines.

You can use multiple pub keys for the same user but is more to explain, but the short answer is to use the same PrivateKey from your Mac on Windows too.