Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Add ssh key to existing droplet in digital ocean

I have the droplet on the digital ocean. I have tried to add ssh key to existing droplet. But there they asked for root password and I don't have root password. I have tried to connect to the droplet through the putty. It is giving message : Unable to use key "home/id_rsa" (OpenSSH SSH-2 private key). How to connect to droplet using ssh key? And What is the proper way to connect to the droplet? Is there any way to add ssh key to the existing droplet?

like image 745
Tejashri Bedarkar Avatar asked Jun 03 '16 08:06

Tejashri Bedarkar


People also ask

How do I add a key to a droplet?

Use OpenSSH to create new SSH keys on MacOS, Linux, or Windows Subsystem for Linux. Use PuTTY to create SSH keys on Windows systems without Bash. Add your SSH key to your Droplets. On DigitalOcean, you can upload your SSH public key to your account, which lets you add it to your Droplets at creation time.


4 Answers

I registered few of the SSH keys for different PCs, so my method is that

1.) Use another pc to login eg.bash (ssh root@yourDropletIP)
2.) Go to your .ssh folder (/.ssh)
3.) Use nano or other text editor to open (nano .ssh/authorized_keys)
4.) Added your new machine ssh-keys to end of the file (notice: check is any empty space between keys, if so, delete it.
5.) Use your new machine to log in and enjoy!!!

like image 133
Shadow Grimes Avatar answered Dec 31 '22 20:12

Shadow Grimes


I have to hack around this process.

  1. Copy your existing SSH key from local machine to a keys.txt file and push to Github.

pbcopy < ~/.ssh/id_rsa.pub

  1. Clone the file to Digital Ocean server and copy to authorized_keys.

cat keys.txt > authorized_keys

like image 31
troydo42 Avatar answered Dec 31 '22 20:12

troydo42


You can reset root password at digital ocean's website.

This function appear at your droplet's "Access" tab.

And you can follow this article to get access to your droplet using ssh-key

https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-putty-on-digitalocean-droplets-windows-users

like image 29
weigreen Avatar answered Dec 31 '22 20:12

weigreen


This may be useful for anyone else who is using Windows with PuTTY.

  1. Change the sshd_config file - set the PasswordAuthentication entry to yes, restart sshd, then login to the droplet via PuTTY.

  2. Copy your public ssh key to the clipboard in Windows. In the PuTTY console, paste the key into the authorized_keys file with a text editor (nano).

  3. Go back into the sshd_config and set PasswordAuthentication back to no.

  4. Restart sshd, logout. Login via PuTTY without a password.

References:

  1. https://www.digitalocean.com/community/tutorials/how-to-use-ssh-keys-with-putty-on-digitalocean-droplets-windows-users

  2. https://www.digitalocean.com/community/tutorials/how-to-create-ssh-keys-with-putty-to-connect-to-a-vps

like image 25
aEon' Avatar answered Dec 31 '22 19:12

aEon'