Ubuntu Server Setup with DigitalOcean

Published May 10th, 2020

When we talk about the "cloud" and the services that run on the Internet such as Facebook and Twitter, we cannot avoid talking about servers. Servers interact with clients over the Internet to provide different services, such as streaming videos, hosting gameplay, and serving content. In this tutorial, you'll learn how to set up your very own server with DigitalOcean, a cloud-hosting provider!

Contents

  1. Introduction
  2. Prerequisites
  3. SSH Keys
  4. DigitalOcean Droplet
  5. Accessing Your Server
  6. Conclusion

Introduction

Alright, let's rewind. What are servers? Servers are just computers that provide services to other client computers over the Internet. Your computer can be a server if you tried hard enough (albeit an insecure one). There are different protocols servers can use to communicate with clients, such as HTTP and FTP. Internally, servers run programs that handle these communications with the client to perform their function.

Nearly every service on the Internet has at least one server behind it. Snapchat? Server. This website? Server. Google? Lots and lots of servers. Take a webpage server; a server that serves HTML files to the client so they can see a webpage (just like this one). The client and server communicate over HTTP, working together to get this HTML file on your screen.

Prerequisites

SSH Keys

If you already have an SSH keypair on your local machine, you can skip this step. SSH is a tool and network protocol that lets us interact with our server using a secure shell terminal. To set this up, we must first generate some cryptographic keys using ssh-keygen.

$ ssh-keygen -t rsa

You can enter where you want the keys to be located, but its nice to keep them in their default locations at ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub by leaving the locations blank.

The id_rsa file is the private key, which should be kept exactly that: private. The id_rsa.pub file is the public key, which will allow the server to communicate with you. The result should look something like this:

$ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (~/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in ~/.ssh/id_rsa.
Your public key has been saved in ~/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:gIv4xUtNCRJ9auLwo+BfTxU/+5s4MC8c1knNzd3GvP8 [email protected]

Head into the DigitalOcean dashboard, and go to Settings -> Security. From there, you should be able to add the SSH public key that you just generated. Open up the id_rsa.pub file and copy-paste the contents into the DigitalOcean interface.

The SSH section in Settings -> Security

DigitalOcean Droplet

Now, we will spin up a DigitalOcean "Droplet", which is a virtual private server. You can think of this as renting your own server for as low as 5 bucks a month.

  1. In the top-right of the DigitalOcean dashboard, click Create
  2. Select "Droplets"
  3. For "image", choose any supported version of Ubuntu (I recommend the latest LTS version)
  4. Choose any plan that suits your needs. For most personal use, the cheapest $5/mo plan works
  5. Select the datacenter closest to your location
  6. Optional: enable Monitoring and IPv6
  7. Select "SSH Keys" for authentication, and check the SSH key that you added to DigitalOcean earlier. This allows you to access your Droplet via SSH
  8. Give your Droplet a readable hostname rather than the pregenerated gibberish
  9. Hit Create Droplet :)
Droplet authentication options; make sure you have "SSH keys" selected

Accessing Your Server

Once your Droplet is done initializing, you should be able to see its public IPv4 address. On the Droplets dashboard, you should see something like this:

Droplet dashboard; you can see your Droplet's IP address here

Copy the IP address to your clipboard; we will use it to SSH into the server. From the same local machine you used to create the SSH keys in the first step, run the following in terminal:

$ ssh [email protected][YOUR DROPLET'S IP HERE]

If all goes well, you should be SSH'ed into your server! You can treat this terminal as if it were directly connected to your server.

Conclusion

This concludes my tutorial on setting up an Ubuntu server on DigitalOcean! Make sure to secure your server and build cool things! I will be coming out with security and development tutorials in the future :)