Today we’re going to set up the server on which we’ll be hosting our app. We’re going to use a company called DigitalOcean for this, for a variety of reasons. The first is that I use them to host CloseBrace and have been very happy with their service. The second is that I think they have one of the easier dashboards to use that I’ve encountered. The third is that they’re quite inexpensive.
If you can’t or do not want to pay for hosting for this application, then you’re basically done with this tutorial series. Everything that’s left is about deployment, and we can’t deploy without a server to deploy to. If you’re an experienced Unix admin, you can probably follow these steps while setting up your own server, and I certainly won’t tell you not to, but it’s not something I’m able to cover here. Server administration is my least favorite thing in the tech world, so I’m going to keep it as simple as possible.
Oh, full disclosure: I am a DigitalOcean affiliate so if you click any of the links to them in this tutorial, and sign up, I will get a small kickback. If this offends you, please feel free to manually edit the link to remove the affiliate code. Or to choose another host entirely, but I’m afraid I can’t provide technical support for, say, Heroku, AWS, Joyent, AppFog, or others, because I haven’t used them!
So, moving on with DigitalOcean … the first thing you’ll need is an account. I’m hoping at this point I don’t need to step you through doing that, because I already have an account and do not want to create a new one. It’s quite straightforward. Head to DigitalOcean.com, click the big blue “sign up” button on the homepage, go through the registration process, confirm your account via email, and you’re good to go. You might also need to add a payment method.
Once you’re at your DigitalOcean dashboard, you’re going to need to create a “droplet” … which is a cloud-based server instance of varying size and speed. For this project, you absolutely will not need more than their most basic droplet, which costs five bucks a month. That’s basically a large latté with tip at Starbucks, so hopefully it’s affordable for most of you. Click the green “create” button in the upper right, choose “droplet,” and you’ll be taken to a droplet customization screen.
We’re going with Ubuntu 16.04.3 x64 here for our distribution. If you want to use FreeBSD or another Unix flavor, I won’t stop you, but some of this tutorial may not work for you and I won’t be able to provide support. Yes, they have “one-click” installs that add things like NodeJS or MongoDB, but it’s actually easier and cleaner to just install it ourselves.
Next, select the $5/month plan. You’ll get half a gig of RAM and 20 gigs of disk space, which is more than enough, though we may have to temporarily create some virtual memory in order to install all of our node modules … that process is a bit memory intensive. If you have money to blow, you can also just select a bigger instance. For the record, CloseBrace is running on the $40/month instance (including a dev and staging server) and not even touching the disk space or transfer requirements.
You do not need block storage at this time, so ignore that option. For datacenter, choose one that’s close to you. CloseBrace runs on New York 3, and is pretty speedy for most users. You don’t need any of the additional options at this time, so ignore them. You will, however, need at least one SSH key so that you can securely connect to your server. So, let’s generate an SSH key. On OS X, you can do that in a terminal window. On Windows, you’ll need a program to do it … but the good news is that program happens to be the best telnet terminal around, so you either already have it, or were going to install it anyway because we’re going to need it.
Let’s start with OS X. Windows users, you can scroll to the next header.
Head for a terminal window, and type:
ssh-keygen -t rsa
You can specify where you want to store your SSH keys, but I strongly recommend just hitting enter and accepting the default location. This stuff’s been around a long time and there’s a reason it has defaults.
You’ll need to type a passphrase in here (twice, actually, so don’t forget it after the first time!). Well, technically you don’t HAVE to … you can use an SSH key without one, but that’s just being insecure for no real reason. This is, essentially, a password that you’ll type when you log in. I like to use the same standards for my SSH passphrases as for my regular website passwords: at least 18 characters long, randomly generated, a mix of letters, numbers, capital letters, and other characters. I store them in my password manager, LastPass. You, however, can choose whatever passphrase you want.
Once you hit enter after confirming your passphrase, the system will generate a public and private key. You should basically never touch your private key for any reason except possibly to delete it. It’s unique to this one machine, and should never be shared with anyone.
All right, time to take care of the Windows users. Mac users, head for "Wrapping It Up."
Hello, Windows users! Sorry you don’t have a built-in SSH generator, but that’s OK. We need PuTTY, which comes with PuTTY Gen for SSH keys, anyway. First things first, you need to install PuTTY, so head to this URL: https://www.chiark.greenend.org.uk/~sgtatham/putty/ … and click the words “Download it here” in the second paragraph. I know this page looks a little unpolished, but trust me, this download is completely secure.
Click the appropriate installer for you, which these days is almost definitely the 64-bit MSI. Download it and run it. I’d show you this part, but I already have PuTTY on my machine. Once it’s installed, open your start menu, type “puttygen” and click on the result. You’ll get a little window with a big empty box that says “no key” and some commands. You don’t need to touch anything here … it’s set to RSA, which is short for SSH-2 RSA, which is what we want. So, click generate, and then move your mouse around erratically until the bar fills up (hooray, entropy!).
Once done, it’ll show you the public key. It’ll also allow you to add a passphrase, which you absolutely should do. It’s more secure, and that’s always valuable. You’ll be typing this in every time you SSH to your server, so make sure you store it somewhere (I recommend a password manager like LastPass). As far as what the passphrase should be, that’s up to you. I like 18 character strings made up of random uppercase and lowercase letters, numbers, and special characters.
Now click “Save Public Key” and choose a place where you’d like to store your keys. A folder in Documents called “ssh keys” is fine. It’s up to you. Once you’ve saved that file, save your private key as well. You never want to link or upload that private key file anywhere. It should be local to the one machine on which you generated it.
Once you’ve saved both keys, you’re done. Head back to Digital Ocean, and let’s continue with the tutorial!
Wrapping It Up
Great. Now everyone has a public SSH key. Hooray!
The public key is what you upload to DigitalOcean. So … do that! Make sure to give it a name you’ll recognize, like “My MacBook Pro” or “That Old 486 I Found Lying Behind the Hot Water Heater In the Basement”
You don’t need any more than one droplets right now, so just leave it at one. You can use their generated hostname, or make up your own (ignore the “add tags” link), and click the big green “create” button.
Congratulations. You can haz droplet. In our next tutorial, we’ll get you connected to it, and start setting things up.