CS 347: Digital Ocean Setup
Your projects and blog will be hosted on a web server that really lives on the web. You will set up your server with Digital Ocean, a company that hosts virtual machines—which they call droplets. Normally, droplets cost money. Thanks to the GitHub Student Developer Pack, you can get a $100 credit for Digital Ocean. This credit supports 20 months of a $5/month droplet, long enough to get you through the semester without spending a penny.
Follow these steps to get an effectively-free droplet.
GitHub Student Developer Pack
The first step is to claim your free credits from GitHub.
- Create an account on GitHub using your JMU address. It takes a few minutes for your account’s student status to be approved.
- Sign up for the GitHub Student Developer Pack.
- Once approved, revisit the GitHub Student Developer Pack. Scroll down to Digital Ocean, click Request your offer code, and copy the revealed offer code.
SSH Key
In a moment you will create a new, public-facing virtual machine hosted on Digital Ocean. The default settings for these virtual machines leave them vulnerable to malicious users, and many of my former students have had their machines compromised. Their passwords were likely brute-force cracked. To keep your machines safe, we will take several steps to harden your server. First, we will disable password logins. Instead, users will authenticate via public and private key pairs.
Users of PuTTY on Windows, follow these directions to set up a public and private key. Save both the public and private keys to files that you can find again.
Users of Linux, macOS, or Windows Subsystem for Linux, run the following command in your terminal:
ssh-keygen -t rsa
The public and private keys will be stored in ~/.ssh/id_rsa.pub
and ~/.ssh/id_rsa
.
Digital Ocean
Now you are ready to create your virtual machine on Digital Ocean.
- Create an account on Digital Ocean using your JMU address. Unfortunately, you need to enter a credit card or Paypal account, even though you won’t be spending any money for this course. If entering a credit card is an impossibility, please let your instructor know.
- In the wizard that appears, click Deploy a virtual machine. Configure the droplet in the following way:
- Distribution: Ubuntu 20.04
- Size/plan: Basic at $5/month
- Data center: somewhere in the US
- Authentication: choose SSH keys and paste in the public key that you generated (PuTTY users, see this note from Digital Ocean)
- Hostname: something meaningful (this is not a domain name; it’s just the droplet’s name that you will see in your Digital Ocean profile)
- Click Billing. Under Promo code, enter your code from the GitHub Student Developer Pack. You should eventually see a balance of $100 appear.
- On the Droplets page, note the IP address of your new droplet.
Be sure to decommission your droplet after the semester is over and before your credit runs out to avoid charges.
SSH
Now you are ready to log in to your new Ubuntu server in the cloud.
- Using the IP address and your private key, log in to your droplet with your favorite SSH client. Users of Windows and PuTTY, follow these directions. Others, execute these commands:
eval `ssh-agent` ssh-add ~/.ssh/id_rsa ssh root@YOUR_IP_ADDRESS
- Running as root is dangerous. Now that you are logged in to your new machine, make a separate account that doesn’t automatically have administrator privileges with this command:
adduser YOUR_USERNAME
ReplaceYOUR_USERNAME
with a username of your choice, preferably in all lowercase letters. Remember your password. - Allow your new account to gain elevated privileges by adding it to the “super users” group with this command:
usermod -aG sudo YOUR_USERNAME
Your new user can now run a command that requires elevated privileges by prefixing it withsudo
and entering your password. - Copy the public key from the root account to this new user’s account with the following commands:
cp -r ~/.ssh /home/YOUR_USERNAME chown -R YOUR_USERNAME /home/YOUR_USERNAME/.ssh
- Log out and ssh back in with your new, non-root account.
Apache
Your next step is to get the web server Apache up and running. While logged in to your droplet, run these commands to install the software:
sudo apt update sudo apt install apache2
Visit http://YOUR_IP_ADDRESS
in your web browser. You should see Apache’s test page.
Whew!