Create Ubuntu Droplet at Digital Ocean
by John Vincent
Posted on May 12, 2018
Article that describes the creation and configuration of a Ubuntu droplet at Digital Ocean and the deployment of the TaskMuncher application.
This is part of a series of discussions regarding Deploying TaskMuncher to a Digital Ocean Droplet.
For more details, please see Deploy TaskMuncher
Create Ubuntu Droplet at Digital Ocean
- Create Droplet
- Ubuntu
16.04 x64 - Standard: $5/month
- Choose a datacenter region
- No SSH key
- Hostname:
taskmuncher
The Ubuntu droplet is created and an IP provided.
Set Root Password
Dashboard
- Select droplet
- Access (left nav)
- Reset Root Password
- Password is emailed.
Get password from your email.
Launch Console
root
- {password-from-your-email}
Change password
How To Connect To Your Droplet with SSH
- Connect to droplet
- ssh root@{your-ip}
The authenticity of host '<your-ip> (<your-ip>)' can't be established.
Are you sure you want to continue connecting (yes/no)?- Yes
Basic user configuration
Add user
adduser {remote-user}{password}
Root privileges
usermod -aG sudo {remote-user}
Create bin directory
cd
mkdir binAdd bin to PATH and add aliases
su - {remote-user}
vi .profile
add
PATH="$HOME/bin:$HOME/.local/bin:$PATH"
lf() { ls -FaC $*; }Basic root configuration
Add aliases to root
sudo -s
vi /etc/bash.bashrc
add
lf() { ls -FaC $*; }Add Public Key Authentication
From Mac
cd .ssh
ssh-keygenEnter file in which to save the key (/Users/<my-user>/.ssh/id_rsa): id_taskmuncher- passphrase: do not provide a passphrase
Generates two files
- private:
id_taskmuncher - public:
id_taskmuncher.pub
Store key in keychain
chmod 600 id_taskmuncher*
ssh-add -K id_taskmuncherAdd to .ssh/config
Host taskmuncher
UseKeychain yes
AddKeysToAgent yes
HostName <your-ip>
User <your-user>
IdentityFile ~/.ssh/id_taskmuncherCopy public key to remote server
cd
cd .ssh
ssh-copy-id <remote-user>@<your-ip>Verify Public Key on Remote Server
- Login to digital ocean droplet
su - <remote-user>- cd .ssh
- view
authorized_keys- Key should be present
- Remove all other keys
Test SSH to Remote Server
ssh <remote-user>@<your-ip>Disable Password Authentication
As root or your sudo user, open the SSH daemon configuration
sudo vi /etc/ssh/sshd_configset:
PasswordAuthentication noensure:
PubkeyAuthentication yes
ChallengeResponseAuthentication noreload the SSH daemon:
sudo systemctl reload sshdTest Log In
ssh <remote-user>@<your-ip>should log in without any passwords.
Script SSH to taskmuncher.com
Optional, from local system, add the following to your bin directory
ssh-to-taskmuncher
#!/bin/sh
#
# script to ssh into the taskmuncher
#
echo "Script to ssh into the taskmuncher"
echo " "
#
REMOTE_SERVER="taskmuncher"
echo " "
echo "Remote Server: $REMOTE_SERVER"
#
ssh "$REMOTE_SERVER"
#
echo " "
echo "Completed"From now on, to access the droplet
ssh-to-taskmuncherRestart Droplet and Test
Before you spend any more time configuring your droplet make sure the access is set up correctly.
- Exit editors etc
As root
shutdown -h nowFrom digitalocean.com dashboard,
- refresh page
- Power
- Notice Droplet is powered down
- Power On
Verify ssh
ssh-to-taskmuncherif any problems here, go back and fix.
Set Up a Basic Firewall
List applications:
sudo ufw app listAvailable applications: OpenSSH
Ensure firewall allows SSH connection:
sudo ufw allow OpenSSHenable the firewall:
sudo ufw enableYou can see that SSH connections are still allowed by typing:
sudo ufw statusAdd Swap
Check System for Swap
sudo swapon -sCheck current disk usage
df -hCreate Swap File
sudo dd if=/dev/zero of=/swapfile bs=1G count=4if this fails with:
dd: memory exhausted by input buffer of size 1073741824 bytes (1.0 GiB)then try:
sudo fallocate -l 4G /swapfileCheck swap file
ls -lh /swapfileEnabling the Swap File
Secure the swap file:
sudo chmod 600 /swapfiletell our system to set up the swap space:
sudo mkswap /swapfileenable the swap:
sudo swapon /swapfileverify:
sudo swapon -sMake the Swap File Permanent
Edit configuration file:
sudo vi /etc/fstabAdd to the end:
/swapfile none swap sw 0 0Tweak your Swap Settings
Current swappiness value by typing:
cat /proc/sys/vm/swappinessFor a VPS system, this number needs to be close to zero.
Edit configuration file:
sudo vi /etc/sysctl.confAt the bottom, add:
vm.swappiness=10Another related value that you might want to modify is the vfs_cache_pressure. This setting configures how much the system will choose to cache inode and dentry information over other data.
cat /proc/sys/vm/vfs_cache_pressure
sudo vi /etc/sysctl.conf
add:
vm.vfs_cache_pressure = 50Check Swap
sudo swapon --summary
free -hInstall Basics
sudo apt-get update
sudo apt-get install zip wgetInstall Node and Npm
Node V8 - Best for Production
curl -sL https://deb.nodesource.com/setup_8.x | sudo -E bash -
sudo apt-get install -y nodejswhich node
/usr/bin/node
which npm
/usr/bin/npm
node -v
v6.11.1
npm -v
v3.10.10Node V6 - Reference Purposes Only
curl -sL https://deb.nodesource.com/setup_6.x | sudo -E bash -
sudo apt-get install -y nodejswhich node
/usr/bin/node
which npm
/usr/bin/npm
node -v
v6.11.1
npm -v
v3.10.10Node V4 - Reference Purposes Only
sudo apt-get update
sudo apt-get install nodejs
sudo apt-get install npmnodejs -v
v4.2.6
npm -v
3.5.2Uninstall
which node
which npmsudo apt-get remove nodejs
sudo apt-get remove npmcd /etc/apt/sources.list.dand remove any node list.
sudo apt-get updateInstall PM2
Use PM2, a production process manager for Node applications with a built-in load balancer.
Shutdown Ghost. Ensure Ghost is shutdown before proceeding.
Install PM2
sudo npm install pm2 -g
pm2 -vInstall HTML-Minifier
sudo npm install html-minifier -gDigital Ocean
- Building and deploying MyTunes to johnvincent.io
- Building and deploying React Github Helper App to johnvincent.io
- Configuring Google Domains
- Create Ubuntu Droplet at Digital Ocean
- Create Ubuntu Droplet at Digital Ocean
- Deploy Feediator to Digital Ocean
- Deploy to Droplet
- Feediator Overview
- Feediator Project
- Maintaining Ubuntu Droplet
- Maintaining Ubuntu Droplet
- Overview of Deployment of a Node API Server
- Overview of johnvincent.io
- Overview of johnvincent.io Jekyll website
- Overview of React Gomoku
- Overview of React Hangman
- Overview of React Lights Out
- Overview of React Yahtzee
- TaskMuncher Overview
Taskmuncher
- Backup TaskMuncher from Digital Ocean
- Configure HTTP Nginx
- Configure HTTPS Nginx
- Configuring Google Domains
- Configuring Meta Tags
- Create Site Map
- Create SSL Certificates
- Create Ubuntu Droplet at Digital Ocean
- Deploy TaskMuncher React App to AWS
- Facebook Application Id
- First time deploy TaskMuncher React App to Digital Ocean
- Google Analytics for TaskMuncher
- Google Authentication
- Google Gmail Configuration
- Google Webmaster Tools
- Install Ubuntu Mongo
- Install Ubuntu Nginx
- Mailgun
- Maintaining Ubuntu Droplet
- Material-UI Showcase
- Optimizing TaskMuncher with Webpack 4
- React Production Issues
- TaskMuncher Images and Favicons
- TaskMuncher Overview
- TaskMuncher Performance
- TaskMuncher Website Validation
- Update SSL Certificates
- Update TaskMuncher for Lighthouse Findings
- Update TaskMuncher to be a Progressive Web App
- Update TaskMuncher to use React BrowserRouter
- Update TaskMuncher to Webpack v4, Babel v7, Material-UI v3
Ubuntu
- Configure HTTP Nginx
- Configure HTTP Nginx
- Configure HTTPS Nginx
- Configure HTTPS Nginx
- Configure PM2
- Create SSL Certificates
- Create SSL Certificates
- Create Ubuntu Droplet at Digital Ocean
- Create Ubuntu Droplet at Digital Ocean
- Deploy Feediator to Digital Ocean
- Install Jekyll Ubuntu
- Install Ubuntu Mongo
- Install Ubuntu Nginx
- Install Ubuntu Nginx
- Maintaining Ubuntu Droplet
- Maintaining Ubuntu Droplet
- SSH to Github
- Update SSL Certificates
- Update SSL Certificates