Question

How do i add an ssh key to an existing droplet?

Posted November 22, 2014 62.5k views

Hello,

I have been trying to add a public key on a pre-existing droplet and I am not able to connect although I have tried to paste it on the original SSH KEY, and on a new key.
I have followed this https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets tutorial, but it is not really showing it well on how i can get into a preconfigured drop-let.

Thank you

1 comment

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.

×
7 answers

You can add an ssh key to an existing droplet by appending the public key (ssh-rsa ...) to /home/user/.ssh/authorized_keys or /root/.ssh/authorized_keys.

If you’re on Linux, you can run the following command to do that automatically:

ssh-copy-id user@123.45.56.78

On OSX, you can run this command instead:

cat ~/.ssh/id_rsa.pub | ssh user@123.45.56.78 "mkdir -p ~/.ssh && cat >>  ~/.ssh/authorized_keys"

i followed this steps https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-digitalocean-droplets and add ssh key to my existing droplet as you say, and now can login with user@ipaddress without password. but when i trying to login as root@ipadress or on other computer as user@ipadress and root@ipaddress, it still asking password except automatically kicking out without being prompted for a password. whats the problem?

btw, i dont sure if my message sent..

Unable to edit my previous post. According to support it is the public key that is entered into the “Add SSH Key” field when creating a new droplet. The respond further, writing, “The [control panel] console does not allow you to use SSH keys. These can only be used for [connecting with SSH via PuTTY or other appropriate client]. The console on your control panel is a VNC style connection intended to be used when you cannot connect via SSH. It can only be used with passwords.” As you see, I edited their text somewhat for clarity.

*Tip: *

If you have forgotten root password then you need to reset the root password.

Just in case you cannot login as root from your computer console, you need to enable root login.

nano /etc/ssh/sshd_config then PermitRootLogin yes and restart ssh service ssh restart.

then proceed as above.

Don’t forget to change PermitRootLogin without-password and restart ssh service service ssh restart or just kill the process ps auxw | grep ssh.

*TIP2: *

If you are using a different ssh key other than id_rsa.pub then modify your ~/.ssh/config file.

The following have worked for me:

  1. Create GitHub repo and put your key in it
  2. Clone the repo using console
  3. Run cat /path/to/cloned/github/project/key | cat >> ~/.ssh/authorized_keys

NB key is a file containing the id_rsa.pub value

I got it to work by adding the ssh key to both /root/.ssh/authorized_keys and /root/.ssh known_hosts then restarting the droplet

Submit an Answer