Report this

What is the reason for this report?

can you help me insert my public key into authorized_keys?

Posted on March 22, 2019

How do I enter my public key? When I access the console from you and open the authorized_keys to place my key it breaks the characters …

I can not access my terminal because I need my key in authorized_keys

can you help me insert my public key into authorized_keys?



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.

Hi there,

the easiest way to copy your public key to your droplet is with SCP. On a typical Linux/macOS machine, you’d do the following:

scp ~/.ssh/id_rsa.pub username@<droplet_IP>:~/.ssh/authorized_keys

where ~/.ssh/id_rsa.pub is the location & name of your public key on your local machine. Also, be sure to replace username with the actual username on your droplet and enter the correct IP. Also, note the colon character between the droplet’s IP and the path of the authorized_keys file on your droplet.

It might also be a good idea to ensure the .ssh directory on your droplet has proper permissions. On your droplet, you might want to run this first:

sudo chmod -R 700 ~/.ssh/

I see. Since you’ve claimed above that the console breaks the characters upon pasting, it’s likely the public key you have pasted that way is corrupted in some way. The fastest way to recover is to start from scratch. If you’re still able to log into your droplet with a password, do so, otherwise log in through the console and remove the .ssh directory entirely:

sudo rm -rf ~/.ssh/

Afterwards, recreate the directory with the proper permissions in place:

mkdir -p ~/.ssh && sudo chmod -R 700 ~/.ssh/

and then follow the instructions I posted in my previous post on how to properly copy your public key file with scp.

Hope this helps!

I get the following error message when I try to run my command from my terminal: Permission denied (publickey). lost connection

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.