Flask App Hosting
Most of my recent apps have been built with Flask, a simple bare bones Python based framework, even this site! Here I will detail my full set up of the web server using Linode, a very reliable VPS provider.
Once you have signed up to Linode, create a $5 nanode with Ubuntu 18.04 LTS, choose it's location and set a strong root password.
Once the nanode has finished booting go to the networking tab and you will see the ip attached to a copyable SSH command. Run this command in your local terminal:
ssh root@yourserverip
Enter the root password you created a moment ago.
Update Ubuntu:
apt update && apt upgrade
Set hostname:
hostnamectl set-hostname yourhostname
hostname
Edit hosts:
vi /etc/hosts
127.0.0.1 localhost
yourserverip yourhostname
Add new user and enter strong password:
adduser yourusername
Add new user to sudoers:
adduser yourusername sudo
Exit and log in as your new user:
exit
ssh yourusername@yourserverip
Create ~/.ssh folder on your server:
mkdir ~/.ssh
On your local machine generate ssh key pair if you don't already have one:
ssh-keygen -b 4096
Copy over your local public key to the server:
scp ~/.ssh/id_rsa.pub yourusername@yourserverip:~/.ssh/authorized_keys
Change permissions on SSH directory and files:
sudo chmod 700 ~/.ssh/
sudo chmod 600 ~/.ssh/*
You may now SSH into your server with just your local SSH key:
exit
ssh yourusername@yourserverip
Disallow root logins over SSH:
sudo vi /etc/ssh/sshd_config
PermitRootLogin no
PasswordAuthentication no
Restart SSH service:
sudo systemctl restart sshd
Install and configure firewall:
sudo apt install ufw
sudo ufw default allow outgoing
sudo ufw default deny incoming
sudo ufw allow ssh
sudo ufw enable
sudo ufw status verbose
In the next part we'll continue setting up the server so we can serve our flask app.