Using SSH Keys
So you are asking yourself “What Hosting Provider Do I choose?”
This is a loaded question as it really depends on what you want to do, what you are capable of doing, and how much you want to spend. Unless you are deploying a .NET application, then Azure is automatically ruled out. There is no need for that headache. Now you are left with UNIX server options and I prefer a Debian-based Linux server, more specifically, a virtual machine running a Debian-based distro of Linux.
Why the virtual machine instead of a shared hosting provider running (probabably) CentOS? I like the control, and it gives me the opportunity to develop multiple sites while maintaining my primary site. I also get to choose which server software I want to use based on my needs. If I am running something very resource heavy that requires a large database I usually opt for NGINX. If I am running a small WordPress, Ghost Blog, or static HTML then I usually go with the ease of Apache.
Many shared hosting providers do offer the ability to SSH into your server and move around your home directory, but your access is greatly restricted and you can’t deploy Node or Python applications (however some shared hosting providers have Ruby on Rails capabilities). I have also found that for as many sites and applications that I manage, the virtual machine route is more cost effective than any other option.
For your own virtual machine with root access at Digital Ocean. it costs $5.00 a month. You can do anything with that machine. You can install NGINX, Apache, Node, Python, git, or any other package available to you. In order for you to be successful in your endeavor to utilize a virtual machine for your hosting it is important to remember that you will need to have a basic understanding of how to change your DNS zone file to point to the IP address of your new VM, and you will need to understand how to use SSH in order to remotely access and maintain your server. I recommend using a public and private key as your authentication method, as it is the most secure option for remote access.
To generate a private and public key pair, open up a terminal window using OSX’s Terminal program, whatever terminal emulator you are running on a Linux distribution, or if you are using Windows you will need a program called Putty and PuttyGen.
Generate SSH Keys
Refer to the PuttyGen documentation regarding generating a key pair if you are using Windows. If you are already on a UNIX based system, then you can issue the following commands:
cd ~/.ssh ssh-keygen
The output of this command will be:
Generating public/private rsa key pair. Enter file in which to save the key (/home/cam/.ssh/id_rsa):
That prompts you to save the file under a different name than the default which is id_rsa. Choose something you will remember. If it is your blog for instance save it as ‘blog’. After naming your key you will recieve another prompt. If you are using a laptop or a computer that no one else uses you will not need to enter anything for this prompt, and you can simply hit ‘ENTER’. The prompt will read
Enter passphrase (empty for no passphrase):
If you left it empty you will confirm this via the next prompt:
Enter same passphrase again:
Hit ‘ENTER’ to continue. You will know that you have successfully completed the process when the following output (varies every key you make) appears:
Your public key has been saved in test.pub. The key fingerprint is: SHA256:4sCg27tyLFIcJ0j3LK+ncmw5kulXNOBkqviiQpXT/e8 cam@drklrohm The key's randomart image is: +---[RSA 2048]----+ | | | . = | |..B * . | |.ooO.* . | |+..+B o S | |o+o = . . | |o+= + . . | |*=+X . . | |**Oo+ .E | +----[SHA256]-----+
We need the public key contents to add to the VM we are about to create so from your Digital Ocean dashboard, click on the green button ‘Create Droplet’. Configure it however you like, I usually choose a blank VM using the latest release of Ubuntu. You will choose your pricing tier. I recommend starting low, and once you are in production with your site or application you can always scale up. On this screen you will choose your data center. I choose San Fransisco because it is closest to me, but you can pick what you like. Finally, at the bottom of the page you will see ‘Add your SSH key’. Here is where we will paste the contents of the public key we just created. In this example I mentioned naming your key ‘blog’, which will have generated two files, one named ‘blog’ and the other named ‘blog.pub’. The ‘blog.pub’ file contains the public key info we will paste into the Digital Ocean interface. To access this data you can simply run:
A ton of nonsensical characters will be printed to your screen and that is what you want to copy. Paste that into the input field on Digital Ocean and in the comment section add the title of this key for future reference. Add the key, rename the ‘hostname’ to something you will recognize and click ‘Create Droplet’.
That’s it. You have a virtual machine running Ubuntu and it is already configured to allow your key ‘blog’. Now you will want to open up your config file (or if you don’t have one it is a good time to create it) by issuing the command:
You should have either a blank terminal text editor window open (or if you have an existing config you should see it now). We will want to configure your new virtual machine in this file for easy access. Add something along the lines of this to your config file:
Host blog HostName IP.OF.YOUR.VM User root
To save this file press Ctrl + O and then Ctrl + C to exit the text editor. Now run the command:
ssh-add blog ssh blog
This will log you in remotely to your new server. You can now install packages via the “apt-get” command and begin taking control of your server and its environment. Leave any questions in the comments section and I will answer them. I know that this does not cover everything, but it gives you the tools to at least take back your server and run it how you see fit.