can you help me insert my public key into authorized_keys?

March 22, 2019 357 views
Initial Server Setup Debian

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?

3 Answers

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 get the following error message when I try to run my command from my terminal:
Permission denied (publickey).
lost connection

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 can not delete the .ssh directory because there are other keys there.

    inside the console of you any relatively large character set is broken the moment I paste the string, my key is ok.

    If I give you my key, can not you add it to me?

Have another answer? Share your knowledge.