From 97a8370caea2fae4a0a67165036aae2dc2d05900 Mon Sep 17 00:00:00 2001 From: Jacob McDonnell Date: Wed, 3 May 2023 13:13:47 -0400 Subject: Rewrite of the website in Flask --- .../__pycache__/dbbak.cpython-310.pyc | Bin 0 -> 471 bytes static/articles/rpilinuxserver/dbbak.py | 8 + .../img/ScreenShot2022-02-19at2.15.13PM.png | Bin 0 -> 17415 bytes .../img/ScreenShot2022-02-19at2.18.39PM.png | Bin 0 -> 21318 bytes .../img/ScreenShot2022-02-19at2.23.20PM.png | Bin 0 -> 70360 bytes .../img/ScreenShot2022-02-19at2.56.21PM.png | Bin 0 -> 79823 bytes .../img/ScreenShot2022-02-19at2.58.29PM.png | Bin 0 -> 66928 bytes static/articles/rpilinuxserver/rpilinuxserver.md | 339 +++++++++++++++++++++ 8 files changed, 347 insertions(+) create mode 100755 static/articles/rpilinuxserver/__pycache__/dbbak.cpython-310.pyc create mode 100755 static/articles/rpilinuxserver/dbbak.py create mode 100755 static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.15.13PM.png create mode 100755 static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.18.39PM.png create mode 100755 static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.23.20PM.png create mode 100755 static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.56.21PM.png create mode 100755 static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.58.29PM.png create mode 100755 static/articles/rpilinuxserver/rpilinuxserver.md (limited to 'static/articles') diff --git a/static/articles/rpilinuxserver/__pycache__/dbbak.cpython-310.pyc b/static/articles/rpilinuxserver/__pycache__/dbbak.cpython-310.pyc new file mode 100755 index 0000000..2b2ab9d Binary files /dev/null and b/static/articles/rpilinuxserver/__pycache__/dbbak.cpython-310.pyc differ diff --git a/static/articles/rpilinuxserver/dbbak.py b/static/articles/rpilinuxserver/dbbak.py new file mode 100755 index 0000000..900780d --- /dev/null +++ b/static/articles/rpilinuxserver/dbbak.py @@ -0,0 +1,8 @@ +db_entry = { + "title": "Hosting a Website on the Raspberry Pi with Rocky Linux", + "date": "02/19/2022", + "file": "static/articles/rpilinuxserver/rpilinuxserver.md", + "desc": "A tutorial on setting up a webserver on a Raspberry Pi with Rocky Linux 8", + "url": "rpilinuxserver", + "id": 1 +} diff --git a/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.15.13PM.png b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.15.13PM.png new file mode 100755 index 0000000..34b57f4 Binary files /dev/null and b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.15.13PM.png differ diff --git a/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.18.39PM.png b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.18.39PM.png new file mode 100755 index 0000000..6ef28ff Binary files /dev/null and b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.18.39PM.png differ diff --git a/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.23.20PM.png b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.23.20PM.png new file mode 100755 index 0000000..cbc9b47 Binary files /dev/null and b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.23.20PM.png differ diff --git a/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.56.21PM.png b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.56.21PM.png new file mode 100755 index 0000000..2482da0 Binary files /dev/null and b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.56.21PM.png differ diff --git a/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.58.29PM.png b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.58.29PM.png new file mode 100755 index 0000000..c952586 Binary files /dev/null and b/static/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.58.29PM.png differ diff --git a/static/articles/rpilinuxserver/rpilinuxserver.md b/static/articles/rpilinuxserver/rpilinuxserver.md new file mode 100755 index 0000000..e89ff5e --- /dev/null +++ b/static/articles/rpilinuxserver/rpilinuxserver.md @@ -0,0 +1,339 @@ +# Hosting a Website on the Raspberry Pi with Rocky Linux + +First Download Rocky Linux for the Raspberry Pi 3 & 4 from +[their website](https://rockylinux.org/alternative-images). + +
+![Screen Shot 2022-02-19 at 2.15.13 PM](/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.15.13PM.png) +
+ +Next you want to burn this image to the sd card that you are going to use. Now +start up the Raspberry Pi and login with the default user `rocky` and the +password is `rockylinux`. + +To make the image take up the whole drive, run: + +

+sudo rootfs-expand
+
+ +Now, you should create a new user: + +

+sudo useradd -m -g users -G wheel userName
+sudo passwd username
+
+ +Next, we should delete the default user so logout and login to your new user: + +

+sudo userdel rocky
+
+ + + +*** + +## Setting a static IP address + +The easiest way is to run: + +

+sudo nmtui
+
+ +
+![Screen Shot 2022-02-19 at 2.18.39 PM](/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.18.39PM.png) +
+ +Select **Edit** a connection and select your network interface. + +
+![Screen Shot 2022-02-19 at 2.23.20 PM](/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.23.20PM.png) +
+ +Select **Show** for **IPv4 CONFIGURATION** and enter the IP you want to set. +Then select **OK** at the bottom, and quit the program. + +## Securing the PI + +### SSH Key Authorization + +The best way to secure the pi is to use an SSH key to login instead of a +password. First you want to generate an SSH key by running on your computer: + +

+ssh-keygen -t rsa
+
+ +Next, to copy your SSH key to your server, run: + +

+ssh-copy-id -i ~/.ssh/mykey user@host
+
+ +To test that it works, run: + +

+ssh -i ~/.ssh/mykey user@host
+
+ +If it worked, you should be able to connect without needing a password. + +To force an SSH key to login, edit `/etc/ssh/sshd_config` using nano or vim. + +Change + +

+PermitRootLogin yes
+PasswordAuthentication yes
+
+to +

+PermitRootLogin no
+PasswordAuthentication no
+
+ +### Setting up fail2ban + +First start and enable firewalld to run at boot: + +

+sudo systemctl start firewalld
+sudo systemctl enable firewalld
+
+ +Now, enable the EPEL repository for Rocky Linux and install fail2ban: + +

+sudo dnf install epel-release -y
+sudo dnf install fail2ban fail2ban-firewalld -y
+
+ +Start and enable fail2ban to run at boot: + +

+sudo systemctl start fail2ban
+sudo systemctl enable fail2ban
+
+ +Now, we have to make fail2ban work with firewalld, run: + +

+sudo mv /etc/fail2ban/jail.d/00-firewalld.conf /etc/fail2ban/jail.d/00-firewalld.local
+sudo systemctl restart fail2ban
+
+ +To create an SSH jail, edit the ssh config file with nano or vim: + +

+sudo nano /etc/fail2ban/jail.d/sshd.local
+
+ +Paste the following into the file and change the values as you see fit: + +

+[sshd]
+enabled = true
+bantime = 1d
+maxretry = 3
+
+ +Save and close the file and restart fail2ban: + +

+sudo systemctl restart fail2ban
+
+ +## Setting up Dynamic DNS with Google Domains + +### Configuring Google Domains + +First, on [Domains.google.com](https://domains.google.com/) go the DNS page for +your domain. Scroll down and click on **Show advanced settings**, Click **Manage +dynamic DNS**, and then click **Create new record**. Enter your subdomain or +leave it black for the domain itself. Finally, click Save. + +### Installing ddclient + +To install ddclient you need to enable the PowerTools Repo for the perl +dependency. + +First, install `dnf-plugins-core`: + +

+sudo dnf -y install dnf-plugins-core
+sudo dnf upgrade
+
+ +Next, enable PowerTools: + +

+sudo dnf config-manager --set-enabled powertools
+
+ +Then, you can install ddclient: + +

+sudo dnf install ddclient
+
+ +Now, we want to edit the config file for ddclient: + +

+sudo nano /etc/ddclient.conf
+
+ +You'll want to look for where it says `protocol=dyndns2`, and enter your +information: + +

+##
+## nsupdate.info IPV4(https://www.nsupdate.info)
+##
+protocol=dyndns2
+use=web, web=http://ipv4.nsupdate.info/myip
+server=domains.google.com
+login=username
+password=password
+domain.tld
+
+ +Wait about 5 minutes and on the Google Domains website, under Dynamic DNS you +should see your IP address under **Data**. + +## Setting up NGINX and Let's Encrypt + +### Installing NGINX + +First, install nginx Webserver: + +

+sudo dnf install nginx
+
+ +Next, start and enable nginx to run at boot: + +

+sudo systemctl start nginx
+sudo systemctl enable nginx
+
+ +Then, check the status to see if it is running: + +

+sudo systemctl status nginx
+
+ +
+![Screen Shot 2022-02-19 at 2.56.21 PM](/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.56.21PM.png) +
+ +Now, we have to allow HTTP traffic through the firewall: + +

+sudo firewall-cmd --add-service=http --permanent
+sudo firewall-cmd --add-service=https --permanent
+sudo firewall-cmd --reload
+
+ +In a web browser, go to the local ip of the server and you should see the nginx +welcome page. + +
+![Screen Shot 2022-02-19 at 2.58.29 PM](/articles/rpilinuxserver/img/ScreenShot2022-02-19at2.58.29PM.png) +
+ +### Configuring NGINX + +First, make your folder for the website, this is where your website will live: + +

+sudo mkdir -p /var/www/websiteName
+
+ +Next, we need to set the proper permissions to make sure everything works: + +

+sudo chown -R nginx /var/www/websiteName
+sudo chmod -R 755 /var/www/websiteName
+
+ +Now, we will create the config file for website: + +

+sudo nano /etc/nginx/conf.d/websiteName.conf
+
+ +and paste the following into the file: + +

+server {
+    listen 80;
+    server_name domain.tld www.domain.tld;
+    root /var/www/websiteName;
+    index index.php index.html index.htm;
+    access_log /var/log/nginx/websiteName.access.log;
+    error_log /var/log/nginx/websiteName.error.log;
+}
+
+ +Now, confirm that the nginx configuration is ok: + +

+sudo nginx -t
+
+ +Restart nginx: + +

+sudo systemctl restart nginx
+sudo systemctl status nginx
+
+ +Next, set SELinux to permissive mode: + +

+sudo setenforce permissive
+sudo getenforce
+
+ +Now, we will need to set SELinux to permissive mode permanently: + +

+sudo sed -i --follow-symlinks 's/SELINUX=enforcing/SELINUX=permissive/g' /etc/sysconfig/selinux
+
+ +### Installing and Running Certbot + +To install Certbot run: + +

+sudo dnf install certbot python3-certbot-nginx
+
+ +To get SSL certificates for your websites run: + +

+sudo certbot --nginx
+
+ +Answer the prompts that show up on screen as you wish. + +To configure auto renewal of the SSL certificate run: + +

+crontab -e
+
+ +and add the following line: + +

+0 12 * * * /usr/bin/certbot renew --quiet
+
+ +This will check everyday at noon to see if the certificate will expire in the +next month, if so it will renew the certificate. + +Now your website should be operational. + -- cgit v1.2.3