2022-05-08 15:29:45 +00:00
= Server setup
2022-05-29 19:13:25 +00:00
== Server specifications
2022-06-28 21:55:17 +00:00
The setup was tested on Debian 11.3. It should also work on other Debian based Linux distributions. For distributions not based on Debian, some modifications might be necessary in the setup script `server_setup.py`.
2022-05-08 15:29:45 +00:00
2022-06-28 21:55:17 +00:00
Two CPU cores should be more than enough for the server.
2022-05-08 15:29:45 +00:00
2022-05-29 19:13:25 +00:00
The needed disk space depends on the database size after long usage.
== Setup
. Root setup
.. `ssh` as `root`:
+
2022-05-08 15:29:45 +00:00
[source,bash]
----
ssh root@SERVER_NAME
----
2022-05-29 19:13:25 +00:00
.. Run the following (as root):
+
2022-05-08 15:29:45 +00:00
[source,bash]
----
# Install needed packages
apt update
2022-05-17 09:58:19 +00:00
apt install sudo python3 git -y
2022-05-08 15:29:45 +00:00
# Add a sudo user with the name 'admin'
sudo useradd admin
sudo usermod -aG sudo admin
sudo mkhomedir_helper admin
# Enter a new password for 'admin'
sudo passwd admin
# Break the SSH connection
exit
----
2022-05-29 19:13:25 +00:00
. Admin setup
2022-05-08 15:29:45 +00:00
2022-05-29 19:13:25 +00:00
.. `ssh` again with the new user `admin` and password:
+
2022-05-08 15:29:45 +00:00
[source,bash]
----
ssh admin@SERVER_NAME
----
2022-05-29 19:13:25 +00:00
.. Clone the repository with `git clone` into `/home/admin/advlabdb`.
2022-05-17 09:58:19 +00:00
2022-05-29 19:13:25 +00:00
.. `cd` into the new cloned repository:
+
2022-05-17 09:58:19 +00:00
[source,bash]
----
cd ~/advlabdb
----
2022-05-29 19:13:25 +00:00
.. Nginx configuration
... Copy the template for the Nginx configuration:
+
2022-05-17 10:46:38 +00:00
[source,bash]
----
cp advlabdb/scripts/setup/advlabdb.conf.template advlabdb/scripts/setup/advlabdb.conf
----
2022-05-29 19:13:25 +00:00
... Change `server_name` in `advlabdb/scripts/setup/advlabdb.conf` to your SERVER_NAME.
2022-05-17 10:46:38 +00:00
2022-05-29 19:13:25 +00:00
.. Environment variables
... Copy the template for the environment variables:
+
2022-05-17 10:46:38 +00:00
[source,bash]
----
cp .env.template .env
----
2022-05-29 19:13:25 +00:00
... Generate secrets for `.env`:
+
2022-05-17 10:46:38 +00:00
[source,bash]
----
python3 advlabdb/scripts/setup/generate_secrets.py
----
2022-05-29 19:13:25 +00:00
... Fill the secrets generated using the last script into `.env`.
2022-05-17 10:46:38 +00:00
2022-05-29 19:13:25 +00:00
... Enter your SERVER_NAME in `.env`.
2022-05-17 09:58:19 +00:00
2022-05-29 19:13:25 +00:00
.. Timezone
2022-05-08 15:29:45 +00:00
2022-05-29 19:13:25 +00:00
... List all available timezones:
+
2022-05-17 11:52:46 +00:00
[source,bash]
----
sudo timedatectl list-timezones
----
2022-05-29 19:13:25 +00:00
... Choose your timezone and enter it as showed while listing as your timezone using this command (with Europe/Berlin as example):
+
2022-05-17 11:52:46 +00:00
[source,bash]
----
sudo timedatectl set-timezone Europe/Berlin
----
2022-05-29 19:13:25 +00:00
.. Edit the file `/etc/hostname` with `sudo` such that its content is only your SERVER_NAME.
2022-05-17 11:52:46 +00:00
2022-05-29 19:13:25 +00:00
.. Edit the file `/etc/hosts` with `sudo` such that the first two lines are:
+
2022-05-17 11:52:46 +00:00
[source,bash]
----
127.0.0.1 localhost
127.0.1.1 SERVER_NAME SERVER_NAME_WITHOUT_DOMAIN
----
2022-05-29 19:13:25 +00:00
.. Run the server setup script:
+
2022-05-17 12:25:51 +00:00
[source,bash]
----
python3 advlabdb/scripts/setup/server_setup.py
----
2022-05-29 19:13:25 +00:00
.. The setup script will cause the server to reboot at the end. After the reboot ssh again:
+
[source,bash]
----
ssh admin@SERVER_NAME
----
2022-05-17 12:25:51 +00:00
2022-05-29 19:13:25 +00:00
.. Change working directory to the repository:
+
2022-05-17 12:25:51 +00:00
[source,bash]
----
cd ~/advlabdb
2022-05-29 19:13:25 +00:00
----
.. Run database initialization script:
+
[source,bash]
----
2022-05-17 12:25:51 +00:00
poetry run python3 -m advlabdb.scripts.setup.init_database
2022-05-29 19:13:25 +00:00
----
.. Restart the gunicorn service:
+
[source,bash]
----
2022-05-17 12:25:51 +00:00
sudo systemctl restart gunicorn
----
2022-05-29 19:13:25 +00:00
.. *Done!* Now go to your SERVER_NAME using a browser to verify that everything is working.
2022-05-17 11:52:46 +00:00
2022-05-29 19:13:25 +00:00
== SSH configuration
IMPORTANT: This section is important for security!
2022-05-08 15:29:45 +00:00
2022-05-29 19:13:25 +00:00
=== SSH key
For the authentication using SSH, generate a SSH key pair on your _own machine_ (not on the server) and upload the public key to the server using the command `ssh-copy-id`:
2022-05-08 15:29:45 +00:00
2022-05-29 19:13:25 +00:00
[source,bash]
----
ssh-copy-id -i KEY.pub admin@SERVER_NAME
----
=== SSH configuration file
On the server, open the file `/etc/ssh/sshd_config` with in an editor like `nano` or `vim` with `sudo`, then do the following:
2022-05-08 15:29:45 +00:00
2022-05-29 19:13:25 +00:00
. Disable login to root
+
Change
+
2022-05-08 15:29:45 +00:00
----
PermitRootLogin yes
----
2022-05-29 19:13:25 +00:00
+
2022-05-08 15:29:45 +00:00
to
2022-05-29 19:13:25 +00:00
+
2022-05-08 15:29:45 +00:00
----
PermitRootLogin no
----
2022-05-29 19:13:25 +00:00
. Disable login with password
+
WARNING: Make sure that you did upload your public key to the server for the SSH authentication! Otherwise, you will not be able to login to the server after this change.
+
Change
+
2022-05-17 23:06:25 +00:00
----
#PasswordAuthentication yes
----
2022-05-29 19:13:25 +00:00
+
2022-05-17 23:06:25 +00:00
to
2022-05-29 19:13:25 +00:00
+
2022-05-17 23:06:25 +00:00
----
PasswordAuthentication no
----
2022-05-29 19:13:25 +00:00
. Disable X11Forwarding
+
Change
+
2022-05-17 23:06:25 +00:00
----
X11Forwarding yes
----
2022-05-29 19:13:25 +00:00
+
2022-05-17 23:06:25 +00:00
to
2022-05-29 19:13:25 +00:00
+
2022-05-17 23:06:25 +00:00
----
X11Forwarding no
----