Add SSH to Existing Droplet
This is a Mac only tutorial. You mileage on windows will vary. I'm sure you can google the different commands and make it work. The droplet I'm using is Ubuntu 14.04
So you need to add an ssh key to your existing "Digital Ocean" droplet? Got a site going and bought a new laptop like this one I'm typing on? Need to be able to access that dev server? Here's the solution.
OK. It's not that hard to do. If I can do it then you certainly can.
First things first....
Do you have an SSH key already generated? Let's check and see if you have one. Type this into your terminal on your mac:
ls -al ~/.ssh
If you have one, you'll get something like this:
Russells-MacBook:~ Home$ ls -al ~/.ssh total 24 drwx------ 5 Home staff 170 May 4 16:17 drwxr-xr-x+ 34 Home staff 1156 May 4 16:38 -rw------- 1 Home staff 1675 May 4 15:59 id_rsa -rw-r--r-- 1 Home staff 411 May 4 15:59 id_rsa.pub -rw-r--r-- 1 Home staff 1386 May 5 20:21 known_hosts Russells-MacBook:~ Home$
If you don't have an SSH key already generated, then you should type this:
ssh-keygen -t rsa
This is a complete tutorial on generating the keys.
The next step is to copy your ssh key to your clipboard. Use this command to copy it:
Type this into the terminal.
pbcopy < ~/.ssh/id_rsa.pub
Once you've generated the keys, and copied the public key to your clipboard then you need to login to your droplet using the password you've been using already.
You should now be at the "message of the day" prompt and have a blinking cursor.
If you've already removed the message of the day, then why are you reading this? You know what to do.
You're logged in right?
The next step is to change directories into the root folder in your droplet. Use the linux command:
You should see something like this:
.. .config .node-gyp tmp .aptitude .gem .npm .v8flags.18.104.22.168.root.json .bash_history .gitconfig npm-debug.log .viminfo .bashrc .local .profile
We are looking for the .ssh folder.
Now we should change directories by typing
cd .ssh into the terminal.
You will need a file titled
authorized_keys. If it's not there, then you will need to use the following command to create it:
If it's already there, then we will need to open it and add our key that is copied to the clipboard. There are numerous ways to edit the file, but I like using
nano for this.
You can use VIM, but then why are you ready this again?
nano authorized_keys into the terminal now.
If there are other keys in there, use your down arrow keys to move to the bottom of the file and press
control v in the terminal to insert your new ssh key into the
authorized_keys file. Then hit
control x. It will ask if you want to write to the file
authorized_keys and you should hit yes and then hit enter.
Logout of your droplet. You should be able to use
ssh root@ip_address to login to the droplet.
"ip_address" is the actual ip address of our droplet
I hope that helps!
Please let me know if something isn't clear or if I've skipped a step. Cheers and happy coding to all and to all a good night!