Report this

What is the reason for this report?

Permission denied (publickey)

Posted on March 16, 2022

I successfully managed to gain access to the server in my terminal through the ssh command. What i can’t do or perform is uploading the static files of my website to the server through the scp command. It provides the error shown above (Permission denied (publickey)). I tried adding my rsa key to the known_hosts file through the droplet console but to no avail. Please assist.

I also tried to delete the files in the known_host file, said yes to the ssh host verification but the same error still finds me. What is the best way to avoid this error?



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!

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.

Hello,

You need to add your public SSH key to the ~/.ssh/authorized_keys file rather than the known_hosts file.

Let me know how it goes!

Best,

Bobby

Hello there,

As per Bobby’s answer, the key must be added in the authorized_keys

You can check our article on How to Upload an SSH Public Key to an Existing Droplet

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

Regards

What worked for me was following the instructions on this page, you edit the local config file in your .ssh dir. This is on top of doing what the others said.

https://www.digitalocean.com/community/tutorials/how-to-configure-custom-connection-options-for-your-ssh-client

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.