DigitalOcean Web Server Configuration and Hosting Multiple Websites

DigitalOcean Initial Ubuntu Server Setup

This article describes essential configuration steps you should follow for digital ocean initial ubuntu server setup.


Step 1: Create a non-root user with sudo rights

In the following code, replace the expression your_username with a username that you like.

# Login to your droplet as root
ssh root@your_server_ip
# Create a non-root user with sudo/admin privileges
adduser your_username
sudo usermod -aG sudo your_username
# Switch from the root to the new username
 su - your_username

Step 2: Set up a basic firewall

In the following code, UFW corresponds to Uncomplicated FireWall. The UFW application is used to enable/disable connections to certain services.

# Enable firewall
sudo ufw enable
# Add SSH service to allow SSH connection
sudo ufw allow OpenSSH

Other useful commands:

# Inspect allowed services/application
sudo ufw status
sudo ufw app list
# Disable UFW 
sudo ufw disable

Step 3: Add SSH keys for automatic authentication

Add SSH keys for automatic authentication without entering a password. From your local machine, type the following bash code:

# Create ssh key if you don't have one
ssh-keygen -t RSA -b 4096 -C "personal_machine"
# Copy the public keys to the droplet’s root account
ssh-copy-id your_username@your_server_ip
# Test your SSH connection by using your new log in credentials
ssh your_username@your_server_ip

Read more: Add SSH Keys to Existing Droplet

Step 4: Add swap

If your server has small RAM, you will need to configure some SWAP, for example 4GB swap.

# Add swap
sudo /bin/dd if=/dev/zero of=/var/swap.1 bs=1M count=4024
sudo /sbin/mkswap /var/swap.1
sudo /sbin/swapon /var/swap.1
sudo sh -c 'echo "/var/swap.1 swap swap defaults 0 0 " >> /etc/fstab'

Version: Français

(Next Lesson) DigitalOcean: How To Install Nginx and SSL
Back to DigitalOcean Web Server Configuration and Hosting Multiple Websites

No Comments

Give a comment

Want to post an issue with R? If yes, please make sure you have read this: How to Include Reproducible R Script Examples in Datanovia Comments