Dev Site - Getting the server setup with Digital Ocean and Arch Linux

Hosting

Virtual Private Server

This website is hosted on a Virtual Private Server (VPS) from Digital Ocean, also called a droplet.

There are several options for hosting, and you don’t even need your own server to do it.

If you do want your own server, Digital Ocean works pretty well. I’ve also used Vultr and Linode in the past, and I’ve had great success with both.

All three options are roughly the same in price, so you could go with any of them. Some of the features each service offer are different, but this website is simple enough that we don’t need anything too fancy.

Ultimately I decided to go with Digital Ocean.

Static Pages

Alternatively, you could use a static website hosting service. I have not used these much in the past so I can’t really comment on them, but the few that I know of are Netlify, GitHub Pages, and GitLab Pages.

GitHub Pages and GitLab Pages interface directly with your repository, so you could remove the entire deployment process by using them.

But I wanted to learn more about deployment with GitLab CI/CD, so I’m sticking with a VPS on Digital Ocean.

Operating System

Assuming you have decided to stick with a VPS, you could use almost any *nix based operating system to host your website on.

I personally love Arch Linux, so I’ll be using that. Arch Linux is very barebones and can require a lot of tinkering, so beware of using it if you do not have a lot of experience with Linux.

However, it’s also a great way to learn how to use Linux, so you may want to give it a try anyway.

Otherwise, Digital Ocean provides several operating systems to choose from by default.

Arch Linux

Because Digital Ocean does not provide an Arch Linux image by default, I will be using the gold image provided by Derek Robson here: https://www.asinine.nz/2019-04-05/Arch-Gold-Image/

He also provides a direct link to the image, which we will use next when creating the droplet.

Digital Ocean Setup

Custom Image

I’m not going to walk you through creating an account and all that, you can figure that out yourself.

Once that’s done however, you will need to upload the custom image to your account so you can create a droplet with it.

So once you’ve logged in, click “Images” on the left and then click “Import via URL”.

On the modal, enter in this URL to the Arch Linux image: https://www.asinine.nz/files/arch_image.img.gz

Hit next. I will keep the image name the same, and choose Arch Linux as the distribution. I will use the New York 3 data center, but you can use whichever one you want.

Add any tags or notes that you want, then click “Upload Image”.

Creating your SSH key

In order to secure your Digital Ocean droplet, one of the best security options is to utilize SSH keys for login.

SSH keys are much more difficult to crack (at least opposed to passwords).

There are multiple ways to generate SSH keys, since I am currently using Windows as my main development environment, I’ll use PuTTY to SSH into the droplet and PuTTYgen (with comes with the PuTTY installer) to generate the SSH keys.

If you’re on Linux, you can use ssh-keygen (see more at https://wiki.archlinux.org/index.php/SSH_keys).

Once you’ve installed PuTTY, open PuTTYgen. For which key you want to generate, I use SSH-2 RSA and 2048 bits. If you want some extra security, you could bump up the number of bits to 4096.

Then click Generate and move your mouse around the blank area to generate some randomness.

Once it’s generated, you should add a key passphrase. It’s not required (and you will login without a password if you leave it blank), but it’s a good idea to have one.

Finally, save both your public key and private key somewhere that you will remember. You will need the private key later once we log into the droplet.

Before closing PuTTYgen, copy the public key text at the top. We’ll need that next to put into your Digital Ocean account.

Adding the SSH key to Digital Ocean

Now go back to Digital Ocean, under Account go to Security. Then click “Add SSH Key” under the SSH keys header.

Paste in the entire text you had previously copied, give it a name, and click Add.

Now we can move into creating the actual droplet (using your new SSH key).

Creating the droplet

Once it’s finally done uploading, you can click “Create” on the top right and then click on “Droplets”.

You’ll want to choose the custom image you just uploaded, then pick a plan. This server isn’t going to be doing anything too crazy, so we can just use the $5/mo option:

We won’t need any block storage for this.

You will need to stick with the same datacenter region that you picked earlier.

Use the SSH key that we added earlier, choose a hostname, enable backups if you want to, and then click “Create Droplet”.

PuTTY configuration

Once the droplet is created, you should get an IP address for your new droplet:

So now open up PuTTY (not PuTTYgen), and we can set up the SSH connection.

Enter in your IP address and leave the default port 22 (we will change this in a later article).

Before you click Open, open up SSH on the left side under Connection, and then click on Auth. Here, we will want to select the private key file that we saved earlier.

One last thing, scroll back up and click on Session. Now enter in a name for your session under “Saved Sessions”, and then click “Save”. This way, you won’t need to re-do this setup later.

Now, click “Open”. You’ll likely get prompted for a security alert because the server’s host key is not in your registry. Click on “Yes” to add it to your cache.

Once you get prompted for login, the default login will be for “root”. Assuming you created a passphrase earlier, you will also have to enter that.

Once that’s done, you’re logged into your new Digital Ocean droplet!

Next Time

In the next article, we will discuss some more configuration with Arch Linux and some extra security steps (particularly disabling root logins).