Add tutorials

This commit is contained in:
Konstantin Protzen 2023-11-17 14:55:27 +01:00
parent 181a2a0b3c
commit d5c46e5233
No known key found for this signature in database
GPG key ID: CECEEDFFC6F845F8
2 changed files with 435 additions and 0 deletions

View file

@ -0,0 +1,215 @@
---
title: Setup of 2FAuth on Ubuntu Standalone
description: Learn how to set up 2FAuth on Ubuntu to secure your logins.
level: beginner
updated_at: 2023-11-16
slug: ubuntu-install-2fauth-standalone
author_name: Konstantin Protzen
author_url: https://github.com/cuzimbisonratte
author_image: https://github.com/cuzimbisonratte.png
author_bio:
tags:
[
linux,
ubuntu,
uptime,
auth,
authentication,
security,
two-factor,
two,
factor,
second,
]
netcup_product_url: https://www.netcup.de/bestellen/produkt.php?produkt=2991
language: en
available_languages: [en, de]
---
# Introduction
# Requirements
For a 'small instance' (just one for yourself and not many users) a VPS 200 is sufficient.
I recommend setting up the instance on a VPS 200.
If you feel like the instance is slowing down, you can always update to a bigger server trough the CCP.
The server needs to have Ubuntu 22.04 already installed.
<hr>
You will also need a domain. A domain used in a webhosting package is sufficient. (You can still use it for your webhosting, because we will use a subdomain.)
# Step 1 - Finding out the IP of your server
1. Log in to the SCP (ServerControlPanel) under https://www.servercontrolpanel.de.
2. Click on the server you want to use.
3. If you are already on the "General" tab, you'll see a pane labeled "Network" in the bottom right corner.
4. Here you can find the IP of your server (under IPv4).
5. Write the IP of your server down.
# Step 2 - Configuring DNS
1. Log in to the CCP (CustomerControlPanel) under https://www.customercontrolpanel.de.
2. In the sidebar on the left, click on "Domains".
3. Find the domain you want to use and click on the magnifying glass symbol next to it.
4. In the new window, click on "DNS".
5. Scroll down until there are empty fields.
6. In the first field, write your subdomain name (This tutorial will use "2fauth").
7. In the dropdown menu, select `A`.
8. In the last field, enter the IP of your server (from Step 1).
9. Click on "Save DNS records".
# Step 3 - Preparing the server
First you need to log in to your server via SSH, then follow these steps:
1. Enter `sudo -s` to get root privileges.
2. If asked for your password, enter it and press `Enter`.
3. Now enter `add-apt-repository ppa:ondrej/php -y && apt update -y && apt upgrade -y` to update the server.
4. If a pink window appears, press `Enter` once to continue.
5. Enter `apt install curl nginx git zip unzip php8.2-fpm php8.2-cli php8.2-gd php8.2-curl php8.2-cli php8.2-bcmath php8.2-mysql php8.2-ctype php8.2-fileinfo php8.2-mbstring php8.2-tokenizer php8.2-xml php8.2-zip -y || curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && snap install certbot --classic` to install all the required software.
6. If a pink window appears, press `Enter` once to continue.
7. Enter `composer update` to update composer. (When asked if you want to continue as root, enter `Yes` and press `Enter` to continue.)
# Step 4 - Installing MariaDB
Follow these steps to install and configure MariaDB:
1. Enter `apt install mariadb-server` to install MariaDB.
2. Run `mysql_secure_installation` to configure MariaDB.
3. You will be asked for the root password. Press `Enter` to continue (there is no password yet).
4. You will be asked if you want to change authentication method. Enter `n` and press `Enter` to continue.
5. You will be asked if you want to set a root password. Enter `n` and press `Enter` to continue.
6. You will be asked if you want to remove anonymous users. Enter `y` and press `Enter` to continue.
7. You will be asked if you want to disallow root login remotely. Enter `y` and press `Enter` to continue.
8. You will be asked if you want to remove the test database and access to it. Enter `y` and press `Enter` to continue.
9. You will be asked if you want to reload privilege tables now. Enter `y` and press `Enter` to continue.
# Step 5 - Creating a database and a user for 2FAuth
1. Enter `mysql -u root` to log in to MariaDB.
2. Enter `CREATE DATABASE 2fauth;` to create the database.
3. Enter `CREATE USER '2fauth'@'localhost' IDENTIFIED BY '<REPLACE_WITH_PASSWORD>';` to create a user. Replace `<REPLACE_WITH_PASSWORD>` with a password of your choice.
4. Enter `GRANT ALL PRIVILEGES ON 2fauth.* TO '2fauth'@'localhost';` to grant the user all privileges.
5. Enter `FLUSH PRIVILEGES;` to apply the changes.
6. Enter `exit;` to exit MariaDB.
# Step 6 - Installing 2FAuth
1. Enter `mkdir /var/www/2fauth && chown www-data 2fauth && cd /var/www/2fauth` to create a directory for 2FAuth.
2. Enter `sudo su -l www-data -s /bin/bash` to switch to the www-data user.
3. Enter `curl https://api.github.com/repos/Bubka/2FAuth/tags | grep "tarball_url" | grep -Eo 'https://[^\"]*' | sed -n '1p' | xargs wget -O - | tar -xz --strip-components=1 -C /var/www/2fauth` to download and extract the latest version of 2FAuth.
4. Enter `cd /var/www/2fauth && composer install --prefer-dist --no-scripts --no-dev && exit` to install the dependencies.
5. Enter `php artisan 2fauth:install` to start the installation.
6. Enter your URL (e.g. `http://2fauth.example.com`) and press `Enter`.
7. Enter `my` and press `Enter` five times to select MariaDB as the database driver.
8. Enter your database users password (from Step 5) and press `Enter`.
# Step 7 - Setup of nginx
2. If asked for your password, enter it and press `Enter`.
3. Enter `mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old && nano /etc/nginx/nginx.conf` to edit the nginx standard config file.
4. Paste the following code into the file:
```nginx
user www-data;
events {}
http {
include mime.types;
access_log /dev/stdout;
error_log /dev/stderr;
server {
listen 80;
server_name 2fauth.example.com;
root /var/www/2fauth/public;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}
```
5. Exit the file by pressing `Ctrl + X`, then `Y` and then `Enter`.
6. Now you can reload nginx by entering `systemctl reload nginx`.
# Step 8 - Setting up HTTPS
1. Enter `certbot --nginx` to start the CertBot setup.
2. I recommend using these settings:
1. Enter your email address.
2. Yes (Terms of Service)
3. No (Advertisement)
4. Press `Enter` to select the only option (your domain).
5. This process can take a while, so please be patient.
# Step 8 - Setting up the Firewall
We need a firewall to protect our server from unwanted connections.
We will use `ufw` (Uncomplicated Firewall) to set up the firewall, because it is easy to use and configure and is also pre-installed on Ubuntu.
1. Enter `ufw allow ssh && ufw allow http && ufw allow https && ufw enable` to allow SSH, HTTP and HTTPS connections and to enable the firewall.
2. Press `Y` and then `Enter` to confirm.
# Step 10 - Setting up 2FAuth
1. Open your browser and go to your subdomain (e.g. `https://2fauth.example.com`).
2. You should see a login screen.
3. Click on "Register" and enter your data.
4. Click on "Register" to register your account. (First account registered will be the admin account.)
I recommend disabling registration after you have registered your account. You can do this by opening the settings and enabling "Disable registration" at the bottom of the page.
# Conclusion
Now you have successfully installed 2FAuth!
From now on your 2FAuth instance will be available under your subdomain (e.g. `https://2fauth.example.com`).
Thank you for using this tutorial!
# Licence
Copyright (c) 2023 Konstantin Protzen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Contributor's Certificate of Origin
By making a contribution to this project, I certify that:
1. The contribution was created in whole or in part by me and I have the right to submit it under the licence indicated in the file; or
2. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate licence and I have the right under that licence to submit that work with modifications, whether created in whole or in part by me, under the same license (unless I am permitted to submit under a different licence), as indicated in the file; or
3. The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
4. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the licence(s) involved.

View file

@ -0,0 +1,220 @@
---
title: Einrichtung von 2FAuth auf Ubuntu Standalone
description: Lerne, wie du 2FAuth auf Ubuntu einrichten und zum sichern deiner Logins verwenden kannst.
level: beginner
updated_at: 2023-11-16
slug: ubuntu-uptime-kuma-standalone-installation
author_name: Konstantin Protzen
translator_url:
translator_name: Konstantin Protzen
author_url: https://github.com/cuzimbisonratte
author_image: https://github.com/cuzimbisonratte.png
author_bio:
tags:
tags:
[
linux,
ubuntu,
uptime,
auth,
authentication,
security,
two-factor,
two,
factor,
second,
]
netcup_product_url: https://www.netcup.de/bestellen/produkt.php?produkt=2991
language: de
available_languages: [en, de]
---
# Einführung
# Anforderungen
Für eine 'kleine Instanz' (nur eine für dich selbst und nicht viele Benutzer) ist ein VPS 200 ausreichend.
Ich empfehle, die Instanz auf einem VPS 200 einzurichten.
Wenn du das Gefühl hast, dass die Instanz langsamer wird, kannst du jederzeit über das CCP auf einen größeren Server upgraden.
Der Server muss bereits Ubuntu 22.04 installiert haben.
<hr>
Du benötigst auch eine Domain. Eine Domain, die in einem Webhosting-Paket verwendet wird, ist ausreichend. (Du kannst sie weiterhin für dein Webhosting verwenden, weil wir eine Subdomain verwenden werden.)
# Schritt 1 - Die IP deines Servers herausfinden
1. Melde dich im SCP (ServerControlPanel) unter https://www.servercontrolpanel.de an.
2. Klicke auf den Server, den du verwenden möchtest.
3. Wenn du bereits auf dem Tab "Allgemein" bist, siehst du unten rechts ein Feld mit der Bezeichnung "Netzwerk".
4. Hier findest du die IP deines Servers (unter IPv4).
5. Schreibe die IP deines Servers auf.
# Schritt 2 - DNS konfigurieren
1. Melde dich im CCP (CustomerControlPanel) unter https://www.customercontrolpanel.de an.
2. Klicke in der linken Seitenleiste auf "Domains".
3. Finde die Domain, die du verwenden möchtest, und klicke auf das Lupensymbol daneben.
4. In dem neuen Fenster, klicke auf "DNS".
5. Scrolle nach unten, bis du leere Felder siehst.
6. In das erste Feld schreibst du den Namen deiner Subdomain (In diesem Tutorial wird "2fauth" verwendet).
7. Wähle im Dropdown-Menü `A` aus.
8. In das letzte Feld gibst du die IP deines Servers ein (aus Schritt 1).
9. Klicke auf "DNS-Einträge speichern".
# Schritt 3 - Vorbereitung des Servers
Zuerst musst du dich über SSH auf deinem Server anmelden, dann folge diesen Schritten:
1. Gib `sudo -s` ein, um Root-Rechte zu erhalten.
2. Wenn nach deinem Passwort gefragt wird, gib es ein und drücke `Enter`.
3. Gib nun `add-apt-repository ppa:ondrej/php -y && apt update -y && apt upgrade -y` ein, um den Server zu aktualisieren.
4. Wenn ein rosa Fenster erscheint, drücke einmal `Enter`, um fortzufahren.
5. Gib `apt install curl nginx git zip unzip php8.2-fpm php8.2-cli php8.2-gd php8.2-curl php8.2-cli php8.2-bcmath php8.2-mysql php8.2-ctype php8.2-fileinfo php8.2-mbstring php8.2-tokenizer php8.2-xml php8.2-zip -y || curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer && snap install certbot --classic` ein, um alle erforderliche Software zu installieren.
6. Wenn ein rosa Fenster erscheint, drücke einmal `Enter`, um fortzufahren.
7. Gib `composer update` ein, um Composer zu aktualisieren. (Wenn gefragt wird, ob du als Root weitermachen möchtest, gib `Ja` ein und drücke `Enter`, um fortzufahren.)
# Schritt 4 - MariaDB installieren
Folge diesen Schritten, um MariaDB zu installieren und zu konfigurieren:
1. Gib `apt install mariadb-server` ein, um MariaDB zu installieren.
2. Führe `mysql_secure_installation` aus, um MariaDB zu konfigurieren.
3. Du wirst nach dem Root-Passwort gefragt. Drücke `Enter`, um fortzufahren (es gibt noch kein Passwort).
4. Du wirst gefragt, ob du die Authentifizierungsmethode ändern möchtest. Gib `n` ein und drücke `Enter`, um fortzufahren.
5. Du wirst gefragt, ob du ein Root-Passwort festlegen möchtest. Gib `n` ein und drücke `Enter`, um fortzufahren.
6. Du wirst gefragt, ob du anonyme Benutzer entfernen möchtest. Gib `y` ein und drücke `Enter`, um fortzufahren.
7. Du wirst gefragt, ob du die Remote-Anmeldung als Root deaktivieren möchtest. Gib `y` ein und drücke `Enter`, um fortzufahren.
8. Du wirst gefragt, ob du die Testdatenbank und den Zugriff darauf entfernen möchtest. Gib `y` ein und drücke `Enter`, um fortzufahren.
9. Du wirst gefragt, ob du die Privilegien-Tabellen jetzt neu laden möchtest. Gib `y` ein und drücke `Enter`, um fortzufahren.
# Schritt 5 - Datenbank und Benutzer für 2FAuth erstellen
1. Gib `mysql -u root` ein, um dich bei MariaDB anzumelden.
2. Gib `CREATE DATABASE 2fauth;` ein, um die Datenbank zu erstellen.
3. Gib `CREATE USER '2fauth'@'localhost' IDENTIFIED BY '<REPLACE_WITH_PASSWORD>';` ein, um einen Benutzer zu erstellen. Ersetze `<REPLACE_WITH_PASSWORD>` durch ein Passwort deiner Wahl.
4. Gib `GRANT ALL PRIVILEGES ON 2fauth.* TO '2fauth'@'localhost';` ein, um dem Benutzer alle Rechte zu gewähren.
5. Gib `FLUSH PRIVILEGES;` ein, um die Änderungen anzuwenden.
6. Gib `exit;` ein, um MariaDB zu verlassen.
# Schritt 6 - 2FAuth installieren
1. Gib `mkdir /var/www/2fauth && chown www-data 2fauth && cd /var/www/2fauth` ein, um ein Verzeichnis für 2FAuth zu erstellen.
2. Gib `sudo su -l www-data -s /bin/bash` ein, um zum Benutzer www-data zu wechseln.
3. Gib `curl https://api.github.com/repos/Bubka/2FAuth/tags | grep "tarball_url" | grep -Eo 'https://[^\"]*' | sed -n '1p' | xargs wget -O - | tar -xz --strip-components=1 -C /var/www/2fauth` ein, um die neueste Version von 2FAuth herunterzuladen und zu extrahieren.
4. Gib `cd /var/www/2fauth && composer install --prefer-dist --no-scripts --no-dev && exit` ein, um die Abhängigkeiten zu installieren.
5. Gib `php artisan 2fauth:install` ein, um die Installation zu starten.
6. Gib deine URL ein (z.B. `http://2fauth.example.com`) und drücke `Enter`.
7. Gib `my` ein und drücke fünfmal `Enter`, um MariaDB als Datenbanktreiber auszuwählen.
8. Gib das Passwort deines Datenbankbenutzers ein (aus Schritt 5) und drücke `Enter`.
# Schritt 7 - Einrichtung von nginx
2. Wenn nach deinem Passwort gefragt wird, gib es ein und drücke `Enter`.
3. Gib `mv /etc/nginx/nginx.conf /etc/nginx/nginx.conf.old && nano /etc/nginx/nginx.conf` ein, um die Standardkonfigurationsdatei von nginx zu bearbeiten.
4. Füge den folgenden Code in die Datei ein:
```nginx
user www-data;
events {}
http {
include mime.types;
access_log /dev/stdout;
error_log /dev/stderr;
server {
listen 80;
server_name 2fauth.example.com;
root /var/www/2fauth/public;
index index.php;
charset utf-8;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location = /favicon.ico { access_log off; log_not_found off; }
location = /robots.txt { access_log off; log_not_found off; }
error_page 404 /index.php;
location ~ \.php$ {
fastcgi_pass unix:/var/run/php/php8.2-fpm.sock;
fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.(?!well-known).* {
deny all;
}
}
}
```
5. Verlasse die Datei, indem du `Strg + X`, dann `Y` und dann `Enter` drückst.
6. Lade nginx neu, indem du `systemctl reload nginx` eingibst.
# Schritt 8 - Einrichten von HTTPS
1. Gib `certbot --nginx` ein, um die CertBot-Einrichtung zu starten.
2. Ich empfehle die Verwendung dieser Einstellungen:
1. Gib deine E-Mail-Adresse ein.
2. Ja (Nutzungsbedingungen)
3. Nein (Werbung)
4. Drücke `Enter`, um die einzige Option (Deine Domain) auszuwählen.
5. Dieser Vorgang kann eine Weile dauern, bitte haben ein wenig Geduld.
# Schritt 8 - Einrichten der Firewall
Du benötigst eine Firewall, um deinen Server vor unerwünschten Verbindungen zu schützen.
Du wirst `ufw` (Uncomplicated Firewall) verwenden, um die Firewall einzurichten, da diese einfach zu bedienen und zu konfigurieren ist und auch auf Ubuntu vorinstalliert ist.
1. Gib `ufw allow ssh && ufw allow http && ufw allow https && ufw enable` ein, um SSH-, HTTP- und HTTPS-Verbindungen zuzulassen und die Firewall zu aktivieren.
2. Drücke `Y` und dann `Enter`, um zu bestätigen.
# Schritt 10 - Einrichten von 2FAuth
1. Öffne deinen Browser und gehen zu deiner Subdomain (z.B. `https://2fauth.example.com`).
2. Du solltest jetzt einen Anmeldebildschirm sehen.
3. Klicke auf "Registrieren" und gib deine Daten ein.
4. Klicke auf "Registrieren", um dein Konto zu registrieren. (Das erste registrierte Konto wird das Administrator-Konto sein.)
Ich empfehle, die Registrierung zu deaktivieren, nachdem du dein Konto registriert hast. Das kannst du tun, indem du die Einstellungen öffnest und am Ende der Seite "Registrierung deaktivieren" aktivierst.
# Fazit
Du hast jetzt erfolgreich 2FAuth installiert!
Ab sofort ist deine 2FAuth-Instanz unter der Subdomain verfügbar (z.B. `https://2fauth.example.com`).
Vielen Dank, dass du dieses Tutorial verwendet hast!
# Licence
[MIT](https://github.com/netcup-community/community-tutorials/blob/main/LICENSE)
Copyright (c) 2023 Konstantin Protzen
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicence, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# Contributor's Certificate of Origin
By making a contribution to this project, I certify that:
1. The contribution was created in whole or in part by me and I have the right to submit it under the licence indicated in the file; or
2. The contribution is based upon previous work that, to the best of my knowledge, is covered under an appropriate licence and I have the right under that licence to submit that work with modifications, whether created in whole or in part by me, under the same licence (unless I am permitted to submit under a different licence), as indicated in the file; or
3. The contribution was provided directly to me by some other person who certified (a), (b) or (c) and I have not modified it.
4. I understand and agree that this project and the contribution are public and that a record of the contribution (including all personal information I submit with it, including my sign-off) is maintained indefinitely and may be redistributed consistent with this project or the licence(s) involved.