A Server is a Physical Computer
There are various types of servers, but they all consist of a physical computer somewhere. This tutorial shows how to set up a server first with the simplest of physical devices you can have in your home for less than $20 and side-by-side with how to do it in its more abstract – and more common – form, a VPS (virtual private server) you can rent from a hosting service.
The two procedures are very analogous. Seeing them side-by-side helps make concrete what you are actually doing even though sometimes you can’t physically see it.
Server 1. Raspberry Pi Zero W Running Raspberry Pi OS (Debian, a flavor of Linux)
Can be purchased many places, such as Microcenter or Amazon.
Server 2. VPS (Virtual Private Server) Running Ubuntu 20.04 (a flavor of Linux)
I purchased a VPS from Hostwinds. There are various operating systems available. I used Ubuntu 20.04.
Connect to Your Server over a Network (or the Internet)
Connect Via Secure Shell (SSH)
I SSH login using the MobaXterm SSH Client. The server is usually a remote computer to which you do not have physical access, so instead of plugging in a keyboard, mouse and screen, you establish a connection that gives you access to the server’s command prompt. SSH stands for secure shell, meaning the data you transfer between your computer and the server are encrypted. SSH is enabled by default in Ubuntu, but not all Linux flavors.
Useful Linux Commands: https://vitux.com/40-most-used-ubuntu-commands/
1. Raspberry Pi Zero W
Connect the Raspberry Pi Zero to your LAN. There is a way to do this with command line but the Raspberry Pi OS connects to WiFi on the initial startup, so just do it on initialization. If you want, to view the saved password with the command line to know generally where WiFi passwords are stored, use
sudo grep psk= /etc/wpa_supplicant/*
which searches the appropriate directory for “psk=” and you see the stored WiFi keys.
Enable SSH. SSH is not enabled by default with Raspberry Pi Zero. Many tutorials tell you to add a blank file to the /boot
folder called SSH
(no extension at all). Use the command touch ssh
, then reboot
. If you do this, notice once SSH is enabled then the file gets deleted so you will not see any change other than the SSH login should work.
Or enable SSH by: in the raspberry pi terminal window, enter sudo raspi-config
, select Interfacing Options
, SSH
, enable it.
2. Ubuntu
Must install openssh-server. Use sudo apt install openssh-server
. Check status after install with sudo systemctl status ssh
.
Find the Raspberry Pi’s own IP address in the command line with ip add
or ip addr
or ifconfig
. The IP will show after wlan0: inet __.__.__.__
Within a LAN, it is often something like 192.168.1.* Alternatively, you can type your router’s IP into your browser and view a list of connected devices. Or, use nmap, sudo apt install nmap
and the command sudo nmap -sn 192.168.1.0/24
(without sudo you won’t see all the MAC addresses)
2. VPS
On a VPS, SSH is (should be) enabled by your host to allow the purchaser to access it. You will get a default username and password from the hosting service who established the VPS with its default settings.
In MobaXterm, “Remote host” is where you specify the IP address of your server, available in your Hostwinds account.
The username is “root”
The password is whatever you set in Hostwinds
Optional: Update Operating System
1. Raspberry Pi OS
sudo apt update
is the Debian update command (Raspberry Pi OS is based on Debian).
2. VPS
Update Ubuntu (only required if there is a new version of Ubuntu).*
*First, be sure you can login as the non-root super-user before updating Ubuntu as the new install will default to not allow root login. This means if you were planning to just use the existing root user with infinite powers you are now infinitely locked out of your own VPS and have to have your host re-initialize it. Your VPS host changed this setting when it set up your VPS so you can login but when you update the Ubuntu OS, the OS returns to the OS default which is to not allow SSH root login! This is a GREAT example of why to do the user basics as the very first step.
sudo do-release-upgrade
Update the advanced package tool:
sudo apt-get update
(without the -get is newer, so I use it)
sudo apt update
Make Website Available Outside Your LAN
1. Raspberry Pi Zero W
Once the Pi server is serving a site on its IP within the LAN, making the site available outside the LAN (on the internet) is as simple as directing site requests that arrive to your internet IP to the Pi server. Sounds complicated, but when a browser looks for a website on the internet, it looks on port 80. Most routers have an option to direct all traffic arriving on a specific port to a specific IP within the LAN. Connect to your network’s router to configure it, usually by entering its IP (often 192.168.1.1) into a browser and logging in with a password you set. You should see an option like this under the advanced settings.
To Do: Establish an SSH Connection with SSH Keys for the Non-Root User
Normally, you generate a public and private key on your local computer then copy the public key to the server along with some settings. Hostwinds has an option in server management to generate the key, download the private key, and install the public key on the server. Reboot required.