Skip to content

Latest commit

 

History

History
1657 lines (858 loc) · 108 KB

README_EN.md

File metadata and controls

1657 lines (858 loc) · 108 KB

Born2beroot-Tutorial 🖥🇬🇧

Index

  1. Download virtual machine ISO 💿

  2. Virtual machine installation 🛠

  3. Debian installation 🌀

  4. Virtual machine setup ⚙️

    4.1 Installing sudo & configuration of users and groups 👤

    4.2 Installing & configuring SSH 📶

    4.3 Installing & configuring UFW 🔥🧱

    4.4 Setting up the sudo policies 🔒

    4.5 Setting up the strong password policy 🔑

    4.6 Connecting via SSH 🗣

  5. Script 🚨

    5.1 Total result of the script 🆗

  6. Crontab ⏰

  7. Signature.txt 📝

  8. Bonus ⭐

    8.1 Manual partition

    8.2 Wordpress & services configuration 🌐

    8.3 Aditional service ➕

  9. Correction sheet ✅

    9.1 Evaluation answers 💯

    9.2 Evaluation commands ⌨️

  10. Tester 🆗

1- Download the virtual machine ISO 💿

CLICK HERE for the URL of the debian ISO. Ths is a direct link to debian.org/download.

2- Installing the virtual machine 🛠

A virtualization software is required to perform the installation. In this tutorial we will use Virtual Box. If you already have installed this software and you have the Debian ISO we can proceed.

1 ◦ We need to open VirtualBox and click New

Captura de pantalla 2022-07-13 a las 18 02 05

2 ◦ We must choose a name for the machine and the folder which will locate it. IMPORTANT Store the machine created inside the sgoinfre folder located in your campus server; this is important because we will run out of memory space in our session and the installation will fail. (Ask your staff if you can't find it)

Screen Shot 2022-10-23 at 2 57 11 PM

3 ◦ Select the total RAM memory which we will reserve for the machine.

Captura de pantalla 2022-07-13 a las 13 06 05

4 ◦ Select the second option so we can create a virtual disk now.

Captura de pantalla 2022-07-13 a las 18 13 24

5 ◦ Choose the first option VDI since we downloaded a ISO.

Captura de pantalla 2022-07-13 a las 18 16 35

6 ◦ Select the first option Dynamically allocated so it will allocate the memory of the fisical machine as it feels necessary while using the virtual machine until we reach the available limit.

Captura de pantalla 2022-07-13 a las 18 19 33

7 ◦ One we established the recommended 12 GB we must click on Create. If we are doing the bonus we might set 30 GB.

Captura de pantalla 2022-07-13 a las 18 25 20

8 ◦ It might seem that we have already finish the installation , but there's still some steps to do. Click on Settings.

Captura de pantalla 2022-07-13 a las 18 30 46

9 ◦ Now click on Storage , again click on the 💿 that we find on the right and click on Choose a disk file.

Captura de pantalla 2022-07-13 a las 18 33 28

10 ◦ Select the ISO that we just downloaded and click Open, then click on Ok.

Captura de pantalla 2022-07-13 a las 18 38 39

  1. ◦ Once all this steps have been completed we can Start our new virtual machine.

Captura de pantalla 2022-07-13 a las 18 44 55

3- Installing Debian 🌀

You there, wait❗️ Your eyesight is important 👀❗️ Making the window bigger will help:

Captura de pantalla 2022-07-13 a las 18 51 41

Use the command key so the machine capture your mouse and vice versa.

Now we proceed 🛠

1 ◦ We will choose the version without graphic interface Install size the subject says so. Any time we want to confirm something Enter key must be pressed, and the Arrow keys must be used any time to move around.

Captura de pantalla 2022-07-13 a las 18 58 48

2 ◦ Now lenguage must be choosed for the machine that will be present during the installation and the default setting. Select English.

Captura de pantalla 2022-07-13 a las 19 00 41

3 ◦ It's time to select the country. If yours no on the pressent list go to Other.

Captura de pantalla 2022-07-13 a las 19 07 50

4 ◦ Time to select continent. In our case we will select Europe 🇪🇺.

Captura de pantalla 2022-07-13 a las 19 09 58

5 ◦ Now select the country. In our case we will select Spain 🇪🇸.

Captura de pantalla 2022-07-13 a las 19 12 01

6 ◦ Choose United States.

Captura de pantalla 2022-07-13 a las 19 13 43

7 ◦ This time it's turn for selecting a keymap. Our keyboard follows the ANSI standard so American English. If you don't know what keyboard standard is yours we higly recommend you to ask your staff.

Captura de pantalla 2022-07-13 a las 19 02 21

8 ◦ Now we must set a Host Name of the machine, which must be your login followed by a 42.

Captura de pantalla 2022-07-13 a las 19 17 23

9 ◦ This section will be left blank since the subject doesn't requiere it.

Captura de pantalla 2022-07-13 a las 19 20 29

10 ◦ We have to set a password for the root user. IMPORTANT Save this password since we need to use the root user. If you want to check the password is correct, try going to Show Pawssword in Clear and then press the Space bar.

Captura de pantalla 2022-07-13 a las 19 21 29

11 ◦ Repeat the process as you need to confirm the password we just set.

Captura de pantalla 2022-07-13 a las 19 24 53

12 ◦ Set up the user name. As is in the subject, we need a new user that isn't the root user, and the name for that user have to be your student login.

Captura de pantalla 2022-07-13 a las 19 26 20

Repeat you user name.

image

13 ◦ And now we have to set our new user password. Just as before, repeat te process; save this password too because it will be used later.

Captura de pantalla 2022-07-13 a las 19 30 08

14 ◦ Select your time zone.

Captura de pantalla 2022-07-13 a las 19 31 41

15 ◦ Select Guied - use entire disk and set up encrypted LVM. ⚠️❗️ If you want to do the bonus select Manual and then click here ❗️⚠️

Captura de pantalla 2022-07-13 a las 19 33 13

16 ◦ We choose the disk wich we wish to create the partition (it only have to show one disk).

Captura de pantalla 2022-07-13 a las 19 40 03

17 ◦ Once we choosed the disk we must make the partition as is in the subject. To do it properly we select the second option Separate /home partition.

Screen Shot 2023-03-08 at 1 44 16 PM

18 ◦ We choose option Yes so the changes will be writen in the disk and so we can set the logical volume manager (LVM).

Captura de pantalla 2022-07-13 a las 19 44 30

19 ◦ We click on Cancel; the erasing of the data is not required.

Captura de pantalla 2022-07-13 a las 19 46 45

20 ◦ Again, we must choose desired password for the LVM encrypt. As is mention before we must repite the process and I advice you to write it down.

Captura de pantalla 2022-07-13 a las 19 51 17

21 ◦ In this step we must input the required amount of volume group to use during the guided partitioning. We can write down max or the total avalaible memory, in this case being 12.4 GB.

Captura de pantalla 2022-07-13 a las 19 55 02

22 ◦ To wrap the partitioning and write the changes in the disk we choose the option Finish partitioning and write changes to disk.

Screen Shot 2023-03-08 at 1 46 17 PM

23 ◦ We choose the option Yes and then we confirm that we do not want more changes.

Screen Shot 2023-03-08 at 1 46 52 PM

24 ◦ We select the option No as is not required addicional packages.

Captura de pantalla 2022-07-13 a las 20 05 42

25 ◦ We choose our Country.

Captura de pantalla 2022-07-13 a las 20 14 23

26 ◦ We choose deb.debian.org as is the recommended by debian itself.

Captura de pantalla 2022-07-13 a las 20 15 00

27 ◦ We will left this option blank and we click on Continue.

Captura de pantalla 2022-07-13 a las 20 17 24

28 ◦ We select the option No as we want to remain out of the stadistics.

Captura de pantalla 2022-07-13 a las 20 21 54

29 ◦ We will left in blank all software choises (with the space bar) and click on Continue.

Captura de pantalla 2022-07-13 a las 20 24 17

30 ◦ We select Yes for install GRUB boot in the hard disk.

Captura de pantalla 2022-07-13 a las 20 26 24

31 ◦ We will choose the device /dev/sda (ata_VBOX_HARDDISK) for the installation for boot loader.

Captura de pantalla 2022-07-13 a las 20 35 46

32 ◦ To finish the installation we click on Continue.

Captura de pantalla 2022-07-13 a las 20 39 30

4- Virtual machine setup ⚙️

➤ First of all, we must select Debian GNU/Linux.

➤ Now we must introduce the encryptation password that we previously set. In my case Hello42bcn.

Captura de pantalla 2022-07-13 a las 20 47 26

➤ After that we must introduce the user and password that we created. In my case the user is gemartin and the password is Hola42spain.

Captura de pantalla 2022-07-13 a las 20 48 38

We have set everything ready for starting the setup of our Debian virtual machine❗️

4.1 - Installing sudo & configuration of user and groups 👤

1 ◦ The beginning of the installation starts with changing user to root so we can install sudo, for this purpouse we write su in the bash prompt and introduce the root password, in my case Hola42bcn. Once we are done we write down the command apt install sudo so the package manager install the required packages for sudo.

Captura de pantalla 2022-07-14 a las 1 36 46

2 ◦ We must reboot machine so the changes can be applied. For that porpouse we will use the commando sudo reboot.

Captura de pantalla 2022-07-14 a las 2 02 24

3 ◦ Once the machine is rebooted we have to input the encryptation password and the login again. To check if sudo have been installed correctly we must switch to root user and then use the command sudo -V; this command will show the sudo version (it will show extra info like the plugins installed). OPTIONAL ➤ In case of the output being too large we can redirect the command output to a file via sudo -V > file.txt and then edit the file using nano file.txt. Other option would be putting | more after the command.

Captura de pantalla 2022-07-14 a las 2 09 59

4 ◦ Now, this step is for the everyone that didn't put his user as the other user asked by the subject during the installation of the system. Still in the root user we will create an aditional user with sudo adduser <login>. If you had already done it will show the same message as is the image.

Captura de pantalla 2022-07-14 a las 2 15 11

5 ◦ We will create a new group called user42. For that we must use sudo addgroup user42.

Screen Shot 2022-10-26 at 6 30 52 PM

🧠 What is GID❓ It's the group identifier, in short, Group 🆔.

🤔 Was the group created without problems? Truth is that there is no sign of one, still we can check it using getent group <groupname> or we can also use cat /etc/group and see all groups and the users in any of them.

6 ◦ With sudo adduser <user> <groupname> we can include a user to a group. We mst include out user in the groups sudo and user42.

Screen Shot 2022-10-26 at 6 32 30 PM

Screen Shot 2022-10-26 at 6 34 09 PM

7 ◦ Once we are done with that we can check it using getent group <groupname> or editing the /etc/group file using nano /etc/group; the groups sudo and user42 must be present with our user.

Screen Shot 2022-10-26 at 6 35 50 PM

Screen Shot 2022-10-26 at 6 36 18 PM

Screen Shot 2022-10-26 at 6 39 22 PM

Screen Shot 2022-10-26 at 6 38 25 PM

4.2 - Installing & configuring SSH 📶

🧠 What is SSH❓ The acronym SSH stands for "Secure Shell." The SSH protocol was designed as a secure alternative to unsecured remote shell protocols. It utilizes a client-server paradigm, in which clients and servers communicate via a secure channel.

1 ◦ First thing, we should update the system using sudo apt update.

Captura de pantalla 2022-07-14 a las 3 09 44

2 ◦ Following up we will install the main tool for remote access with the SSH protocol, using OpenSSH. The installation requieres the package sudo apt install openssh-server. When we are asked for confirmation we will write y, and just then the installation will proceed.

Captura de pantalla 2022-07-14 a las 3 14 52

Anywan curious that the installation have been realices without problems we can use sudo service ssh status and it will show how is the state of it. Active must be show to continue.

Captura de pantalla 2022-07-14 a las 3 53 59

3 ◦ Going on, some files have been created and we need to configur them. For that we will use Nano or VIM (we will need to install vim since it's not preinstalled using sudo apt install vim) or any other text editor. First file that we will edit will be /etc/ssh/sshd_config. If you are not on root you will not be able to edit the file; as you know, for switching to root we use su.

Captura de pantalla 2022-07-14 a las 3 24 21

4 ◦ The # means that line it is commented; the lines that we will be edit have to be uncommented. Once we are editing the file we need to update the following lines:

➤ #Port 22 -> Port 4242

Captura de pantalla 2022-07-14 a las 3 31 04

➤ #PermitRootLogin prohibit-password -> PermitRootLogin no

Captura de pantalla 2022-07-14 a las 3 34 13

When finish we have to save the changes and leave the file.

5 ◦ Now with the file /etc/ssh/ssh_config. (not sshd_config)

Captura de pantalla 2022-07-14 a las 3 48 56

Edit the following line:

➤ #Port 22 -> Port 4242

Captura de pantalla 2022-07-14 a las 3 50 29

6 ◦ Finally we must restart the ssh service so it can be updated. For that purpuse we will use sudo service ssh restart and once it is done we will check the service state with sudo service ssh status and confirm that everything is alright.

Captura de pantalla 2022-07-14 a las 3 56 56

4.3 Installing & configuring UFW 🔥🧱

🧠 What is UFW It is a firewall which use the command line for setting up iptables using a small number of easy commands.

1 ◦ First things first, we need to install the packages for UFW, for that we will use sudo apt install ufw, then when we are asked for confirmation type y and the installation will proceed

Captura de pantalla 2022-07-14 a las 19 28 55

Captura de pantalla 2022-07-14 a las 19 29 25

2 ◦ When we are done with it, we want to start it using the command sudo ufw enable and then it have to show us the the firewall is ative.

Captura de pantalla 2022-07-14 a las 19 32 57

3 ◦ Then we must allow our firewall to accept the connections that will happens in the 4242 port. What we will do is use sudo ufw allow 4242.

Captura de pantalla 2022-07-14 a las 19 34 12

4 ◦ Lastly we will check if everything done here is correct checking the actual state of our firewall. For that we will use sudo ufw status. Alternatively sudo ufw status verbose or sudo ufw status numbered can be used.

Captura de pantalla 2022-07-14 a las 19 38 37

4.4 Setting up the sudo policies 🔒

1 ◦ Begining with this section, we will create a file in /etc/sudoerd.d/. The file will serve the purpouse of storing our sudo policy. The command that we will use will be touch /etc/sudoers.d/sudo_config.

Captura de pantalla 2022-07-14 a las 22 00 40

2 ◦ Then we must create a directory as is asked in the subject in /var/log/ because each commands need to be logged, the input and output. We will use mkdir /var/log/sudo for our folder.

Captura de pantalla 2022-07-14 a las 21 56 53

3 ◦ We must edit the file that we created in the first step of this section. Use any text editor, but for this guide as is in every screenshot we will use nano. Use nano /etc/sudoers.d/sudo_config.

Captura de pantalla 2022-07-14 a las 22 04 10

4 ◦ Once we are editing the file we must set it up with the following commands.

Defaults  passwd_tries=3
Defaults  badpass_message="Mensaje de error personalizado"
Defaults  logfile="/var/log/sudo/sudo_config"
Defaults  log_input, log_output
Defaults  iolog_dir="/var/log/sudo"
Defaults  requiretty
Defaults  secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"

➤ As it should be on the file.

Captura de pantalla 2022-07-16 a las 2 03 45

🤔 What does each command❓

F5B5BED3-C144-4EDF-91AB-226533DD5B18_4_5005_c

🟩 GREEN -> Total tries for entering the sudo password.

🟥 RED -> The message that will show when the password failed.

🟨 YELLOW -> Path where will the sudo logs will be stored.

🟦 BLUE -> What will be logged.

🟫 BROWN -> TTY is required lol.

🟪 PURPLE -> Folders that will be excluded of sudo

4.5 Setting up a strong password policy 🔑

1 ◦ First step will be editing the login.defs file.

Captura de pantalla 2022-07-16 a las 2 54 06

2 ◦ Once we are done editing the file, we will set the next parameters:

➤ PASS_MAX_DAYS 99999 -> PASS_MAX_DAYS 30

➤ PASS_MIN_DAYS 0 -> PASS_MIN_DAYS 2

Captura de pantalla 2022-07-16 a las 3 05 49

PASS_MAX_DAYS: It's the max days till password expiration.

PASS_MIN_DAYS: It's the min days till password change.

PASS_WARN_AGE: It's the days till password warning.

3 ◦ For continuing the installation we must install the next packages with the following commandsudo apt install libpam-pwquality , then we wrute Y so we can continue; we wait till it finish.

Captura de pantalla 2022-07-16 a las 3 13 52

4 ◦ Next thing we must do is is edit a file and change itś content. We will use nano /etc/pam.d/common-password.

Captura de pantalla 2022-07-16 a las 3 27 02

5 ◦ After retry=3 we must add the following commands:

minlen=10
ucredit=-1
dcredit=-1
lcredit=-1
maxrepeat=3
reject_username
difok=7
enforce_for_root

➤ This is how the line must be↙️

Captura de pantalla 2022-07-16 a las 3 34 33

➤ This is how the file must look ↙️

Captura de pantalla 2022-07-16 a las 3 38 08

🤔 What does each command❓

minlen=10 ➤ The minimun characters a password must contain.

ucredit=-1 ➤ The password at least have to contain a capital letter. We must write it with a - sign, as is how it knows that's refering to minumum caracters; if we put a + sign it will refer to maximum characters.

dcredit=-1 ➤ The passworld at least have to containt a digit.

lcredit=-1 ➤ The password at least have to contain a lowercase letter.

maxrepeat=3 ➤ The password can not have the same character repited three contiusly times.

reject_username ➤ The password can not contain the username inside itself.

difok=7 ➤ The password it have to containt at least seven diferent characters from the last password ussed.

enforce_for_root ➤ We will implement this password policy to root.

4.6 Connecting via SSH 🗣

1 ◦ If we want to connect via SSH we must close the machine and go to settings.

Captura de pantalla 2022-07-18 a las 10 15 13

2 ◦ Once there we will click on Network, click on Advanced so it shows more options, then we click on Port fowarding.

Captura de pantalla 2022-07-18 a las 10 18 32

3 ◦ Click on the emoji for adding a new rule.

Captura de pantalla 2022-07-18 a las 10 21 24

4 ◦ Lastly we will add the 4242 port to host and client. The IP's are not required. We will click accept so changes can be saved.

Captura de pantalla 2022-07-18 a las 10 22 29

➤ To connect via ssh from the machine to the virstual machine using and the use the command ssh <user>@localhost -p 4242; it will ask for the password of the user that we are trying to log in. Once the password is introduced it will show or login in green, that will mean that the connections has been successfully.

Screen Shot 2022-10-27 at 12 40 23 AM

Screen Shot 2022-10-27 at 12 40 04 AM

5- Script 🚨

Going into this part, you need to take special atention to everything, as is important to learn all that is here. Do not cheat this part! You will be asked how the script works during the evaluation, or as the evaluator sees.

🧠 What is a script❓ It is a sequence of commands stored in a file that when executed will do the function of each command.

5-1 Architecture

For the architecture of the SO to be shown, you will use the command uname -a ("-a" == "--all"). What this command does is print all information, except if the CPU is unknow or the platform hardware.

Screen Shot 2022-10-27 at 4 50 06 PM

5-2 Physical Cores

For the number of fisical cores to be shown we will use the file /proc/cpuinfo, which give us information about the CPU: its type, brand, model, performance, etc. We will use grep "physical id" /proc/cpuinfo | wc -l with the command grep looking inside the file "physical id" and with wc -l to count the line of the grep output.

Screen Shot 2022-10-27 at 4 50 49 PM

5-3 Virtual Cores

To show the number of virtual cores is very similar to the previous one. We will again use the file /proc/cpuinfo, but in this case we will use the command grep processor /proc/cpuinfo | wc -l. The usage is practically the same as before, only that instead of counting the lines of "physical id" we will do it with "processor". We do it this way for the same reason as before, the way of quantifying marks 0 if there is a processor.

Screen Shot 2022-10-27 at 4 55 48 PM

5-4 RAM

To show the RAM memory we will use the command free to see at the moment information about the RAM, the used part, free, reserved for other resources, etc. For more info about the command we will put free --help. We will use free --mega since that unit of measure appears in the subject.

Captura de pantalla 2022-08-02 a las 2 46 10

Once we have run this command, we must filter our search since we do not need all the information that it provides. The first thing we need to show is the used memory, for which we will use the command awk, which processes data based on text files, that is, we can use the data that interests us from a file. Finally, what we will do is compare if the first word of a row is equal to "Mem:" we will print the third word of that row, which will be the used memory. The whole command together would be free --mega | awk '$1 == "Mem:" {print $3}'. In the script the return value of this command will be assigned to a variable that will be concatenated with other variables so that everything is the same as specified in the subject.

Captura de pantalla 2022-08-02 a las 2 55 21

To obtain the total memory, the command is practically the same as the previous one, the only thing we must change is that instead of printing the third word of the row, we want the second one free --mega | awk '$1 == "Mem:" {print $2}'.

Captura de pantalla 2022-08-02 a las 3 00 02

Finally, we must calculate the % of used memory. The command is again similar to the previous ones, the only modification we will make is in the printing part. As the operation to get the percentage is not exact, it can give us many decimals and in the subject only 2 appear, so we will do the same, that is why we use %.2f so that only 2 decimals are shown. Another thing you may not know is that in printf to show a % you have to put %%. The whole command free --mega | awk '$1 == "Mem:" {printf("(%.2f%%)\n", $3/$2*100)}'.

Captura de pantalla 2022-08-02 a las 3 51 01

5-5 Disk memory

To view the occupied and available memory of the disk, we will use the df command, which stands for "disk filesystem", it is used to get a complete summary of the use of disk space. As indicated in the subject, the used memory is shown in MB, so we will then use the -m flag. Next, we will do a grep to only show us the lines that contain "/dev/" and then we will do another grep with the -v flag to exclude lines that contain "/boot". Finally, we will use the awk command and sum the value of the third word of each line to once all the lines are summed, print the final result of the sum. The entire command is as follows: df -m | grep "/dev/" | grep -v "/boot" | awk '{memory_use += $3} END {print memory_use}'.

Captura de pantalla 2022-08-03 a las 2 26 15

To obtain the total space, we will use a very similar command. The only differences will be that the values we will sum will be $2 instead of $3 and the other difference is that in the subject the total size appears in Gb, so as the result of the sum gives us the number in Mb we must transform it to Gb, for this we must divide the number by 1024 and remove the decimals.

Screen Shot 2023-03-14 at 8 54 34 PM

Finally, we must show a percentage of the used memory. To do this, again, we will use a command very similar to the previous two. The only thing we will change is that we will combine the two previous commands to have two variables, one that represents the used memory and the other the total. Once we have done this, we will perform an operation to obtain the percentage use/total*100 and the result of this operation will be printed as it appears in the subject, between parentheses and with the % symbol at the end. The final command is this: df -m | grep "/dev/" | grep -v "/boot" | awk '{use += $3} {total += $2} END {printf("(%d%%)\n"), use/total*100}'.

Captura de pantalla 2022-08-03 a las 2 49 33

5-6 CPU usage percentage

To view the percentage of CPU usage, we will use the vmstat command, which shows system statistics, allowing us to obtain a general detail of the processes, memory usage, CPU activity, system status, etc. We could put no option but in my case I will put an interval of seconds from 1 to 4. We will also use the tail -1 command, which will allow us to produce the output only on the last line, so of the 4 generated, only the last one will be printed. Finally, we will only print word 15, which is the available memory usage. The entire command is as follows: vmstat 1 4 | tail -1 | awk '{print $15}'. The result of this command is only part of the final result since there is still some operation to be done in the script for it to be correct. What should be done is to subtract the amount returned by our command from 100, the result of this operation will be printed with one decimal and a % at the end and the operation would be finished.

Captura de pantalla 2022-08-03 a las 0 33 39

5-7 Last reboot

To see the date and time of our last restart, we will use the who command with the -b flag, as this flag will display the time of the last system boot on the screen. As has happened to us before, it shows us more information than we want, so we will filter it and only show what we are interested in, for this we will use the awk command and compare if the first word of a line is "system", the third word of that line will be printed on the screen, a space, and the fourth word. The entire command would be as follows: who -b | awk '$1 == "system" {print $3 " " $4}'.

Captura de pantalla 2022-08-02 a las 12 24 58

5-8 LVM active

To check if LVM is active or not, we will use the lsblk command, which shows us information about all block devices (hard drives, SSDs, memories, etc) among all the information it provides, we can see lvm in the type of manager. For this command we will do an if because we will print Yes or No. Basically, the condition we are looking for will be to count the number of lines in which "lvm" appears and if there are more than 0 we will print Yes, if there are 0 we will print No. The entire command would be: if [ $(lsblk | grep "lvm" | wc -l) -gt 0 ]; then echo yes; else echo no; fi.

Captura de pantalla 2022-08-02 a las 22 38 43

5-9 TCP connections

To check the number of established TCP connections, we will use the ss command replacing the now obsolete netstat. We will filter with the -ta flag so that only TCP connections are shown. Finally, we will do a grep to see those that are established as there are also only listening and close with wc -l to count the number of lines. The command is as follows: ss -ta | grep ESTAB | wc -l.

Captura de pantalla 2022-08-03 a las 0 53 36

5-10 Number of users

We will use the users command which will show us the names of the users there are, knowing this, we will put wc -w to count the number of words in the command output. The entire command is as follows: users | wc -w.

Captura de pantalla 2022-08-02 a las 12 33 29

5-11 IP adress & MAC

To obtain the host address, we will use the hostname -I command and to obtain the MAC, we will use the ip link command which is used to show or modify the network interfaces. As more than one interface, IP's etc. appear, we will use the grep command to search for what we want and thus be able to print only what is requested. To do this, we will put ip link | grep "link/ether" | awk '{print $2}' and in this way we will only print the MAC.

Captura de pantalla 2022-08-02 a las 14 53 14

5-12 Number of commands executed with sudo

To obtain the number of commands executed with sudo, we will use the journaclctl command, which is a tool that is responsible for collecting and managing the system logs. Next, we will put _COMM=sudo in order to filter the entries by specifying its path. In our case we put _COMM because it refers to an executable script. Once we have filtered the search and only the sudo logs appear, we still need to filter a bit more as when you start or close the root session it also appears in the log, so to finish filtering we will put a grep COMMAND and this will only show the command lines. Finally, we will put wc -l so that the lines are numbered. The entire command is as follows: journalctl _COMM=sudo | grep COMMAND | wc -l). To check that it works correctly, we can run the command in the terminal, put a command that includes sudo and run the command again and it should increase the number of sudo executions.

Captura de pantalla 2022-08-02 a las 23 50 39

5-13 Total result of the script

⚠️ Remember not to copy and paste if you do not know the function of each command. ⚠️

#!/bin/bash

# ARCH
arch=$(uname -a)

# CPU PHYSICAL
cpuf=$(grep "physical id" /proc/cpuinfo | wc -l)

# CPU VIRTUAL
cpuv=$(grep "processor" /proc/cpuinfo | wc -l)

# RAM
ram_total=$(free --mega | awk '$1 == "Mem:" {print $2}')
ram_use=$(free --mega | awk '$1 == "Mem:" {print $3}')
ram_percent=$(free --mega | awk '$1 == "Mem:" {printf("%.2f"), $3/$2*100}')

# DISK
disk_total=$(df -m | grep "/dev/" | grep -v "/boot" | awk '{disk_t += $2} END {printf ("%.1fGb\n"), disk_t/1024}')
disk_use=$(df -m | grep "/dev/" | grep -v "/boot" | awk '{disk_u += $3} END {print disk_u}')
disk_percent=$(df -m | grep "/dev/" | grep -v "/boot" | awk '{disk_u += $3} {disk_t+= $2} END {printf("%d"), disk_u/disk_t*100}')

# CPU LOAD
cpul=$(vmstat 1 2 | tail -1 | awk '{printf $15}')
cpu_op=$(expr 100 - $cpul)
cpu_fin=$(printf "%.1f" $cpu_op)

# LAST BOOT
lb=$(who -b | awk '$1 == "system" {print $3 " " $4}')

# LVM USE
lvmu=$(if [ $(lsblk | grep "lvm" | wc -l) -gt 0 ]; then echo yes; else echo no; fi)

# TCP CONNEXIONS
tcpc=$(ss -ta | grep ESTAB | wc -l)

# USER LOG
ulog=$(users | wc -w)

# NETWORK
ip=$(hostname -I)
mac=$(ip link | grep "link/ether" | awk '{print $2}')

# SUDO
cmnd=$(journalctl _COMM=sudo | grep COMMAND | wc -l)

wall "	Architecture: $arch
	CPU physical: $cpuf
	vCPU: $cpuv
	Memory Usage: $ram_use/${ram_total}MB ($ram_percent%)
	Disk Usage: $disk_use/${disk_total} ($disk_percent%)
	CPU load: $cpu_fin%
	Last boot: $lb
	LVM use: $lvmu
	Connections TCP: $tcpc ESTABLISHED
	User log: $ulog
	Network: IP $ip ($mac)
	Sudo: $cmnd cmd"

Script viewed from nano ↙️

Captura de pantalla 2022-08-03 a las 3 47 31

Result after executing the script ↙️

Captura de pantalla 2022-08-03 a las 3 46 15

6- Crontab ⏰

🧠 What is crontab?It is a background process manager. The specified processes will be executed at the time you specify in the crontab file.

To properly configure crontab, we must edit the crontab file with the following command sudo crontab -u root -e.

In the file, we must add the following command for the script to execute every 10 minutes */10 * * * * sh /ruta del script.

Captura de pantalla 2022-08-03 a las 4 40 18

Operation of each crontab parameter:

m ➤ Corresponds to the minute at which the script will be executed, the value ranges from 0 to 59.

h ➤ The exact hour, the 24-hour format is used, the values range from 0 to 23, with 0 being 12:00 midnight. dom ➤ refers to the day of the month, for example, you can specify 15 if you want to execute every day 15.

dow ➤ means the day of the week, it can be numeric (0 to 7, where 0 and 7 are Sunday) or the first three letters of the day in English: mon, tue, wed, thu, fri, sat, sun.

user ➤ Defines the user who will execute the command, it can be root, or another user as long as it has permission to execute the script.

command ➤ Refers to the command or the absolute path of the script to be executed.

7- Signature.txt 📝

To obtain the signature, the first thing we must do is shut down the virtual machine, since once you turn it on or modify something, the signature will change.

Captura de pantalla 2022-08-03 a las 4 47 32

The next step will be to locate ourselves in the path where we have the .vdi of our virtual machine.

Screen Shot 2022-08-03 at 4 57 37 AM

Finally, we will run shasum machinename.vdi and this will give us the signature. The result of this signature is what we will need to add to our signature.txt file and subsequently upload the file to the intra repository. It is very important not to reopen the machine since the signature will be modified. For corrections, remember to clone the machine so you can turn it on without fear of changing the signature.

🧠 What is shasum❓ It is a command that allows you to identify the integrity of a file using the SHA-1 hash check sum of a file.

Screen Shot 2022-08-03 at 4 58 48 AM

8- Bonus ⭐️

8.1- Manual partition

1 ◦ When choosing disk partitioning, we will select manual. This way we can edit the partitions one by one.

Screen Shot 2022-10-23 at 4 30 48 PM

2 ◦ In this section, it shows us a general description of our partitions and mount points. Currently, we do not have any partitions. To create a new partition table, we must choose the device where we want to create them. In our case, we will choose the only one available.

Screen Shot 2022-10-23 at 4 35 39 PM

3 ◦ We accept the confirmation message. Basically, it warns us that if there are already partitions on the device, they will be deleted and that if we are sure to create a new empty partition table.

Screen Shot 2022-10-23 at 4 36 08 PM

4 ◦ Once we have completed the previous step, we can see how our partition table appears empty. Now we must configure it, for this we must select it.

Screen Shot 2022-10-23 at 4 36 35 PM

5 ◦ We will create a new partition.

Screen Shot 2022-10-23 at 4 36 54 PM

We will start by creating this:

image

6 ◦ As the subject indicates, the size of the partition must be 500 megabytes.

Screen Shot 2022-10-23 at 4 37 27 PM

7 ◦ We choose the type of partition. We choose primary because it will be the partition where the Operating System will be installed.

Screen Shot 2022-10-23 at 4 37 38 PM

Brief description of all types of partitions:

Primary: The only partition on which an OS can be installed. There can only be 4 primary partitions per hard drive or 3 primary and one extended.

Secondary/Extended: It was designed to break the 4 primary partition limitation on a single physical disk. There can only be one partition of this type per disk, and it only serves to contain logical partitions.

Logical: It occupies a portion of the primary/extended partition or the whole of it, which has been formatted with a specific type of file system (in our case we will use ext4) and has been assigned a unit, so the operating system recognizes the logical partitions or its file system. There can be a maximum of 23 logical partitions in an extended partition, however, Linux, the OS we are currently working with, reduces it to 15, more than enough for this project.

8 ◦ We will select beginning because we want the new partition to be created at the beginning of the available space.

Screen Shot 2022-10-23 at 4 37 52 PM

9 ◦ In the following screenshot it shows the details of the partition. We will modify the mount point as specified in the subject.

Screen Shot 2022-10-23 at 4 38 27 PM

10 ◦ We choose boot as the mount point for our partition.

Screen Shot 2022-10-23 at 4 38 49 PM

11 ◦ We finish configuring the current partition.

Screen Shot 2022-10-23 at 4 39 07 PM

12 ◦ Once we have completed the previous step, the partition should already appear. Now we must create a logical partition with all the available space on the disk, which has no mount point and is encrypted. To do this, we select the free space where we want to create it.

Screen Shot 2022-10-23 at 4 39 37 PM

image

13 ◦ We create a new partition.

Screen Shot 2022-10-23 at 4 39 58 PM

14 ◦ We select the maximum size.

Screen Shot 2022-10-23 at 4 40 26 PM

15 ◦ We select the type of partition, in this case logical.

Screen Shot 2022-10-23 at 4 40 53 PM

16 ◦ We will modify the mount point.

Screen Shot 2022-10-23 at 4 41 44 PM

17 ◦ We will choose the option not to mount it.

Screen Shot 2022-10-23 at 4 42 11 PM

18 ◦ We finish configuring the current partition.

Screen Shot 2022-10-23 at 4 42 41 PM

19 ◦ We will configure encrypted volumes. This way we can encrypt our partition.

Screen Shot 2022-10-23 at 4 43 08 PM

20 ◦ We accept the confirmation message.

Screen Shot 2022-10-23 at 4 43 27 PM

21 ◦ We create the encrypted volumes.

Screen Shot 2022-10-23 at 4 43 46 PM

22 ◦ We select which partition we want to encrypt.

Screen Shot 2022-10-23 at 4 44 06 PM

23 ◦ We finish configuring the current partition.

Screen Shot 2022-10-23 at 4 44 35 PM

24 ◦ We finish because we don't want to create more encrypted volumes.

Screen Shot 2022-10-23 at 4 44 49 PM

25 ◦ We accept the confirmation message. It tells us that everything inside the partition will be encrypted and it should not take long to finish.

Screen Shot 2022-10-23 at 4 45 06 PM

26 ◦ We don't care if it takes a long time or not, we cancel it because there is nothing to encrypt since the partition is empty.

Screen Shot 2022-10-23 at 4 45 27 PM

27 ◦ Again we must enter a password, this time it will be the encryption phrase. As I previously mentioned, you must repeat the process and write it down as it will be important in the future.

Screen Shot 2022-10-23 at 4 48 38 PM

28 ◦ We repeat the encryption phrase.

Screen Shot 2022-10-23 at 4 49 01 PM

29 ◦ We will configure the logical volume manager.

Screen Shot 2022-10-23 at 4 50 17 PM

30 ◦ We will accept the confirmation message as we agree to save the changes to the disk.

Screen Shot 2022-10-23 at 4 50 42 PM

31 ◦ We will create a new volume group. Volume groups group partitions.

Screen Shot 2022-10-23 at 4 52 04 PM

32 ◦ We will enter the name we want to give it. LVMGroup as indicated in the subject.

Screen Shot 2022-10-23 at 4 52 58 PM

33 ◦ We will select the partition where we want to create the group.

Screen Shot 2022-10-23 at 4 53 22 PM

34 ◦ Now we must create all the logical partitions. As we have to repeat the same actions several times, there are captures that will not be documented.

image

Screen Shot 2022-10-23 at 4 53 50 PM

35 ◦ We will start by choosing the group where we want them to be created. We select the only one available (the one we just created).

Screen Shot 2022-10-23 at 4 54 02 PM

36 ◦ The order of creation of the logical units will be the same as indicated in the subject, so we will start with root and end with var-log. Then we will select the name of the logical volume.

Screen Shot 2022-10-23 at 4 55 42 PM

37 ◦ Size, as indicated in the subject, will be 10g.

Screen Shot 2022-10-23 at 4 56 21 PM

38 ◦ We repeat the process for swap. We only change the name and size.

Screen Shot 2022-10-23 at 4 56 49 PM

Screen Shot 2022-10-23 at 4 57 26 PM

Screen Shot 2022-10-23 at 4 57 41 PM

Screen Shot 2022-10-23 at 4 58 11 PM

39 ◦ We repeat the process for home. We only change the name and size.

Screen Shot 2022-10-23 at 4 58 57 PM

Screen Shot 2022-10-23 at 4 59 07 PM

Screen Shot 2022-10-23 at 5 01 13 PM

Screen Shot 2022-10-23 at 5 04 34 PM

40 ◦ We repeat the process for var. We only change the name and size.

Screen Shot 2022-10-23 at 5 05 10 PM

Screen Shot 2022-10-23 at 5 05 30 PM

Screen Shot 2022-10-23 at 5 06 03 PM

41 ◦ We repeat the process for srv. We only change the name.

Screen Shot 2022-10-23 at 5 06 14 PM

Screen Shot 2022-10-23 at 5 06 39 PM

Screen Shot 2022-10-23 at 5 06 57 PM

Screen Shot 2022-10-23 at 5 07 13 PM

42 ◦ We repeat the process for tmp. We only change the name.

Screen Shot 2022-10-23 at 5 07 34 PM

Screen Shot 2022-10-23 at 5 07 46 PM

Screen Shot 2022-10-23 at 5 07 55 PM

Screen Shot 2022-10-23 at 5 08 19 PM

43 ◦ Finally, we repeat the process for var-log. We only change the name and size.

Screen Shot 2022-10-23 at 5 08 34 PM

Screen Shot 2022-10-23 at 5 08 40 PM

Screen Shot 2022-10-23 at 5 08 59 PM

Screen Shot 2022-10-23 at 5 09 28 PM

44 ◦ Once we have completed all the previous steps, we will finish the configuration of the logical volume manager.

Screen Shot 2022-10-23 at 5 09 51 PM

45 ◦ Now we can see how in the section where it shows us all our partitions and free space, all the logical partitions that we just created are already appearing. Good, we must configure all of them to select the file system that we want and the mount point indicated in the subject. Again we will go in order and select the first one that appears, which is home.

Screen Shot 2022-10-23 at 5 10 36 PM

46 ◦ Show us the configuration of the partition. We must choose a file system as it currently does not have one.

Screen Shot 2022-10-23 at 5 10 55 PM

47 ◦ Choose the Ext4 file system, it is the most commonly used file system in Linux distributions.

Screen Shot 2022-10-23 at 5 11 18 PM

48 ◦ Now we need to select the mount point.

Screen Shot 2022-10-23 at 5 11 44 PM

49 ◦ We select home as indicated in the subject.

Screen Shot 2022-10-23 at 5 11 54 PM

50 ◦ Once we have selected it, we will finish the configuration of the partition.

Screen Shot 2022-10-23 at 5 12 10 PM

51 ◦ Again, these steps can become very repetitive so I won't comment much. We repeat everything the same way (except for the mount point) for root.

Screen Shot 2022-10-23 at 5 13 36 PM

Screen Shot 2022-10-23 at 5 13 53 PM

Screen Shot 2022-10-23 at 5 14 08 PM

Screen Shot 2022-10-23 at 5 14 22 PM

Screen Shot 2022-10-23 at 5 14 39 PM

Screen Shot 2022-10-23 at 5 14 52 PM

52 ◦ Repeat the process for srv and change the mount point.

Screen Shot 2022-10-23 at 5 15 05 PM

Screen Shot 2022-10-23 at 5 15 31 PM

Screen Shot 2022-10-23 at 5 15 37 PM

Screen Shot 2022-10-23 at 5 15 44 PM

Screen Shot 2022-10-23 at 5 15 52 PM

Screen Shot 2022-10-23 at 5 16 04 PM

53 ◦ For swap, we will make an exception because the file system will be different. We select swap.

Screen Shot 2022-10-23 at 5 16 32 PM

54 ◦ At the time of selecting the file system, we leave it on swap area.

Screen Shot 2022-10-23 at 5 16 41 PM

55 ◦ Once the previous step is completed, we will finish the partition configuration.

Screen Shot 2022-10-23 at 5 16 59 PM

Screen Shot 2022-10-23 at 5 17 09 PM

56 ◦ Now we will do the same thing as before, but now we will do it with tmp and changing the mount point.

Screen Shot 2022-10-23 at 5 17 41 PM

Screen Shot 2022-10-23 at 5 17 49 PM

Screen Shot 2022-10-23 at 5 18 01 PM

Screen Shot 2022-10-23 at 5 18 08 PM

Screen Shot 2022-10-23 at 5 18 24 PM

Screen Shot 2022-10-23 at 5 18 40 PM

57 ◦ We repeat the process again for var, changing the mount point.

Screen Shot 2022-10-23 at 5 19 13 PM

Screen Shot 2022-10-23 at 5 19 21 PM

Screen Shot 2022-10-23 at 5 19 28 PM

Screen Shot 2022-10-23 at 5 19 36 PM

Screen Shot 2022-10-23 at 5 19 51 PM

Screen Shot 2022-10-23 at 5 20 00 PM

58 ◦ Finally, we repeat the process again for var-log. In this case, we will have to manually enter the mount point..

Screen Shot 2022-10-23 at 5 20 23 PM

image

image

image

image

image

image

59 ◦ Once we have completed all of the previous steps, we are almost finished. We must click 'finish partitioning' to save all of the changes to the disk.

image

60 ◦ We accept the message and the changes will be saved. Make sure that all of the partitions look the same as in the screenshot.

image

61 ◦ We select the option No because we do not need additional packages.

Captura de pantalla 2022-07-13 a las 20 05 42

62 ◦ We choose our Country.

Captura de pantalla 2022-07-13 a las 20 14 23

63 ◦ We choose deb.debian.org because, considering our region, it is where we will have the best connection.

Captura de pantalla 2022-07-13 a las 20 15 00

64 ◦ We will leave this option empty and click directly on Continue.

Captura de pantalla 2022-07-13 a las 20 17 24

65 ◦ We selected the option No because we do not want developers to see our statistics even though they are anonymous.

Captura de pantalla 2022-07-13 a las 20 21 54

66 ◦ We will remove all the software options (using the spacebar) and press Continue.

Captura de pantalla 2022-07-13 a las 20 24 17

67 ◦ We will select Yes to install GRUB boot on the hard drive.

Captura de pantalla 2022-07-13 a las 20 26 24

68 ◦ We will choose the device for the bootloader installation /dev/sda (ata_VBOX_HARDDISK).

Captura de pantalla 2022-07-13 a las 20 35 46

69 ◦ We will press Continue to finish the installation.

Captura de pantalla 2022-07-13 a las 20 39 30

70 ◦ Once we have finished with the installation of Debian, we must set up our virtual machine.

Click here to navigate to the virtual machine settings ⚙️

8.2 - Wordpress & services configuration 🌐

Lighttpd

🧠 What is Lighttpd❓ Lighttpd is a web server designed to be fast, secure, flexible, and standards-compliant. It is optimized for environments where speed is a top priority because it consumes less CPU and RAM than other servers.

1 ◦ Installation of Lighttpd packages.

Screen Shot 2022-10-27 at 4 09 24 AM

2 ◦ We allow connections through port 80 with the command sudo ufw allow 80.

Screen Shot 2022-10-27 at 4 15 24 AM

3 ◦ We check that we have actually allowed it. Port 80 and allow should appear.

Screen Shot 2022-10-27 at 4 15 45 AM

4 ◦ We add the rule that includes port 80. If you don't remember how to add rules in port forwarding. Machine configuration → Network → Port forwarding → Replicate the capture

Screen Shot 2022-11-18 at 2 49 56 PM

WordPress

🧠 What is Wordpress❓ It is a content management system focused on the creation of any type of website.

1 ◦ To install the latest version of WordPress we must first install wget and zip. To do this we will use the following command sudo apt install wget zip.

🧠 What is wget❓ It is a command line tool used to download files from the web.

🧠 What is zip❓ It is a command line utility for compressing and decompressing files in ZIP format.

Screen Shot 2022-11-18 at 2 45 11 PM

2 ◦ Once we have installed the packages we must locate ourselves in the folder /var/www/ with the command cd we will access it cd /var/www/.

Screen Shot 2022-11-18 at 2 45 53 PM

3 ◦ Once we are in the path /var/www/ we must download the latest version of WordPress. As my native language is Spanish I will select the latest version in Spanish. We will use the following command: sudo wget https://es.wordpress.org/latest-es_ES.zip.

Screen Shot 2022-11-18 at 2 47 00 PM

4 ◦ Unzip the file you just downloaded with the command sudo unzip latest-en_US.zip.

Screen Shot 2022-11-18 at 2 47 25 PM

5 ◦ We will rename the folder html and call it html_old. sudo mv html/ html_old/.

Screen Shot 2022-11-18 at 2 48 21 PM

6 ◦ Now we will rename the wordpress folder and call it html. sudo mv wordpress/ html.

Screen Shot 2022-11-18 at 2 48 49 PM

7 ◦ Finally we will set these permissions on the html folder. We will use the command sudo chmod -R 755 html. The number 7 indicates that the owner has read, write and execute permissions. The number 5 indicates that the group and others only have read and execute permissions.

Screen Shot 2022-11-18 at 2 49 17 PM

Mariadb

🧠 What is MariaDB❓ It is a database. It is used for various purposes, such as data warehousing, e-commerce, enterprise-level functions, and logging applications.

1 ◦ We will install the packages with the command sudo apt install mariadb-server

Screen Shot 2022-10-27 at 4 17 09 AM

2 ◦ Because the default configuration leaves your MariaDB installation unsecure, we will use a script provided by the mariadb-server package to restrict access to the server and remove unused accounts. We will run the script with the following command sudo mysql_secure_installation. It will ask if we want to switch to Unix socket authentication. Since we already have a protected root account we will type N.

Switch to unix_socket autentication? → N
Change the root password? → N
Remove anonymous users? → Y
Disallow root login remotely? → Y
Remove test database and acces to it? → Y
Reaload privilege tables now? → Y

Screen Shot 2022-10-27 at 4 19 25 AM

Screen Shot 2022-10-27 at 1 00 20 AM

Screen Shot 2022-10-27 at 1 00 40 AM

Switch to unix_socket authentication? We choose N because we don't want it to switch to Unix socket authentication because we already have a protected root account.

Change the root password? We choose N. We do not want to change the root password. By default we have no password but in mariadb he is not really root as we must give him administrator permissions.

Remove anonymous users? We choose Y. By default when you install mariadb it has an anonymous user, which allows anyone to log into mariadb without having to create their own user account. This is designed for testing purposes and to make the installation smoother. When we leave the development environment and want to move to a production environment we must remove the anonymous users.

Disallow root login remotely? Choose Y. Disabling root login remotely will prevent anyone from guessing the root password. We will only be able to connect to root from localhost.

Remove test database and access to it? Choose Y. This will remove the test database and any users who have access to it.

Reaload privilege tables now? Choose Y. This will reload the MySQL permission tables so that the changes to the security settings will take effect immediately.

1 ◦ Once we have finished with the installation of mariadb we must create the database and the user for the WordPress. First we must access mariadb.

Screen Shot 2023-03-31 at 12 16 28 AM

2 ◦ We create a database for the WordPress. In my case I'm going to call it wp_database. I will do all this with the command CREATE DATABASE wp_database;.

Screen Shot 2023-03-31 at 9 53 17 PM

3 ◦ To make sure that the database for WordPress has been created we can view all existing databases with the command SHOW DATABASES;.

Screen Shot 2023-03-31 at 9 54 04 PM

4 ◦ Next we need to create a user inside the database. We will use the command CREATE USER 'gemartin'@'localhost' IDENTIFIED BY '12345';.

Screen Shot 2023-03-31 at 9 56 59 PM

5 ◦ We bind the new user to our database so that we grant him the necessary permissions to be able to work. We will use the command GRANT ALL PRIVILEGES ON wp_database.* TO 'gemartin'@'localhost';.

Screen Shot 2023-03-31 at 10 01 32 PM

6 ◦ We update the permissions for the changes to take effect with the command FLUSH PRIVILEGES;.

Screen Shot 2023-03-31 at 10 02 01 PM

7 ◦ Once we have completed the previous step, we can exit mariadb.

Screen Shot 2023-04-01 at 10 43 40 PM

PHP

🧠 What is PHP❓ It is a programming language. It is mainly used to develop dynamic web applications and interactive websites. PHP runs on the server side.

1 ◦ We install the necessary packages to be able to run web applications written in PHP language and that need to connect to a MySQL database. Run the following command sudo apt install php-cgi php-mysql.

Screen Shot 2023-03-31 at 10 07 04 PM

WordPress configuration

1 ◦ Access the /var/www/html directory with the command: cd /var/www/html.

Screen Shot 2023-04-01 at 8 26 46 PM

2 ◦ Copy the file wp-config-sample.php and rename it wp-config.php

Screen Shot 2023-04-01 at 8 28 42 PM

3 ◦ Once we have renamed it we will edit the file wp-config.php nano wp-config.php and modify the following values.

Screen Shot 2023-04-01 at 8 42 25 PM

You have to replace them with the values that we have previously set when we created the database and the user so that WordPress can connect and make use of it.

Screen Shot 2023-04-01 at 8 46 08 PM

4 ◦ We enabled the fastcgi-php module in Lighttpd to improve the performance and speed of web applications on the server. sudo lighty-enable-mod fastcgi

image

5 ◦ We enabled the fastcgi-php module in Lighttpd to improve the performance and speed of PHP-based web applications on the server. sudo lighty-enable-mod fastcgi-php

image

6 ◦ We update and apply the changes in the configuration with the command sudo service lighttpd force-reload.

image

7 ◦ Once we have completed the previous steps we can go back to our browser and type localhost. You should see the following:

Screen Shot 2023-04-01 at 8 49 00 PM

Screen Shot 2023-04-01 at 8 00 38 PM

8 ◦ We must fill in all the fields. In my case I have put the following:

Screen Shot 2023-04-01 at 8 02 29 PM

9 ◦ Once we have filled in all the fields we must click on Install WordPress and we will have finished the installation. You will see the next tab. Now WordPress can create the tables and dump all the data it needs to work in the database we have assigned to it.

Screen Shot 2023-04-01 at 8 02 52 PM

10 ◦ If we access again to our localhost from the browser we can see our functional page.

Screen Shot 2023-04-01 at 9 02 51 PM

11 ◦ If we want to access the admin panel to make changes to our site we will have to put in the browser localhost/wp-admin and log in with our account.

Screen Shot 2023-04-01 at 9 05 41 PM

Screen Shot 2023-04-01 at 9 06 44 PM

12 ◦ Once you have logged in, you can modify whatever you like. Customizing the page is optional, as it is not specified in the subject of this guide, we will not deal with it.

Screen Shot 2023-04-01 at 9 07 38 PM

8.3 - Aditional service ➕

LiteSpeed ⚡️

🧠 What is LiteSpeed❓ It is a proprietary web server software. It is the fourth most popular web server, and is estimated to be used by 10% of websites.

1 ◦ Before installing any software, it is important to ensure that the system is up to date.

sudo apt update

Screen Shot 2022-11-25 at 2 59 17 AM

sudo apt upgrade

Screen Shot 2022-11-25 at 3 00 18 AM

2 ◦ By default, OpenLiteSpeed is available in the Debian 11 base repository. So, you must run the following command to add the OpenLiteSpeed repository to your Debian system:

wget -O - https://repo.litespeed.sh | sudo bash

As the command is long, I connected via ssh.

Screen Shot 2022-11-25 at 3 05 49 AM

3 ◦ Again, we update the packages and install OpenLiteSpeed.

sudo apt update

Screen Shot 2022-11-25 at 3 07 31 AM

sudo apt install openlitespeed

Screen Shot 2022-11-25 at 3 11 22 AM

4 ◦ The default password for OpenLiteSpeed is 123456. We will change the password to something more secure with the following command.

sudo /usr/local/lsws/admin/misc/admpass.sh

Screen Shot 2022-11-25 at 3 12 33 AM

5 ◦ We configure the firewall to allow connections through ports 8088 and 7080. We then add the rules in the port forwarding.

sudo ufw allow 8088/tcp

Screen Shot 2022-11-25 at 3 15 39 AM

sudo ufw allow 7080/tcp

Screen Shot 2022-11-25 at 3 15 59 AM

sudo ufw reload

Screen Shot 2022-11-25 at 3 16 18 AM

Port forwarding rules.

Screen Shot 2022-11-25 at 3 16 52 AM

6 ◦ Once we have completed the previous step we can connect. We will put in the search engine of our browser localhost:7080 we provide our login credentials and we will have access to everything.

Screen Shot 2022-11-25 at 3 18 53 AM

Screen Shot 2022-11-24 at 8 49 24 PM




This tutorial has taken a lot of work, if you think it has been useful I would greatly appreciate a starred 🌟 so that it can be shared and help more students 👨🏻‍🎓❤️




9- Correction sheet ✅

Screen Shot 2022-10-15 at 10 29 57 PM (1)

Screen Shot 2022-10-15 at 10 30 26 PM

Screen Shot 2022-10-15 at 10 30 57 PM

Screen Shot 2022-10-15 at 10 31 12 PM

9.1 Evaluation answers 💯

▪️ What is a virtual machine❓

It is software that simulates a computer system and can run programs as if it were a real computer. It allows the creation of multiple simulated environments or dedicated resources from a single physical hardware system.

▪️ Why you have chosen Debian❓

This is a personal thing for everyone, my opinion: The subject itself explains that it is easier to do it in Debian and if you look for documentation/tutorials there are many and all of them have been done in debian.

▪️ Basic differences between CentOS and Debian

182516961-c3e4da77-2db8-4737-a68f-27b033908705 (1) (1)

▪️ What is the purpose of virtual machines❓

Their purpose is to provide a hardware platform and operating system independent execution environment, which hides the details of the underlying platform and allows a program to always run the same way on any platform.

▪️ Differences between apt and aptitude ↙️

Aptitude is an enhanced version of apt. APT is a lower-level package manager and aptitude is a high-level package manager. Another big difference is the functionality offered by both tools. Aptitude offers better functionality compared to apt-get. Both are able to provide the necessary means to perform package management. However, if you are looking for a more feature-rich approach, Aptitude should be it.

▪️ What is APPArmor❓

A security module in the Linux kernel that allows the system administrator to restrict the capabilities of a program.

▪️ What is LVM❓

It is a logical volume manager. It provides a method for allocating space on mass storage devices, which is more flexible than conventional partitioning schemes for storing volumes.

9-2 Evaluation commands ⌨️

1 ◦ Verify that no graphical interface is in use.

We will use the command ls /usr/bin/*session and it should give the same result as in the screenshot. If anything different appears, a graphical interface is being used.

Screen Shot 2022-11-25 at 12 00 02 AM

2 ◦ Check that the UFW service is in use.

sudo ufw status

Screen Shot 2022-11-24 at 1 25 06 AM

sudo service ufw status

Screen Shot 2022-11-24 at 1 25 37 AM

3 ◦ Check that the SSH service is in use.

sudo service ssh status

Screen Shot 2022-11-24 at 1 26 43 AM

4 ◦ Check that you are using the Debian or Centos operating system.

uname -v o uname --kernel-version

Screen Shot 2022-11-24 at 1 37 17 AM

5 ◦ Check that your user is within the "sudo" and "user42" groups.

getent group sudo

getent group user42

Screen Shot 2022-11-24 at 3 26 30 AM

6 ◦ Create a new user and show that it follows the password policy we have created.

sudo adduser name_user and enter a password that follows the policy.

Screen Shot 2022-11-24 at 3 29 45 AM

7 ◦ We create a new group named "evaluating".

sudo addgroup evaluating

Screen Shot 2022-11-24 at 3 30 47 AM

8 ◦ We add the new user to the new group.

sudo adduser name_user evaluating

Screen Shot 2022-11-24 at 3 33 08 AM

To verify that it has been entered correctly.

Screen Shot 2022-11-24 at 3 33 31 AM

9 ◦ Check that the machine's hostname is correct login42.

Screen Shot 2022-11-24 at 3 37 27 AM

10 ◦ Modify hostname to replace your login with the evaluator's. In this case, we will replace it with student42.

sudo nano /etc/hostname and replace our login with the new one.

Screen Shot 2022-11-24 at 3 42 30 AM

Screen Shot 2022-11-24 at 3 43 47 AM

sudo nano /etc/hosts and replace our login with the new one.

Screen Shot 2022-11-24 at 3 44 08 AM

Screen Shot 2022-11-24 at 3 44 35 AM

Reboot the machine.

Screen Shot 2022-11-24 at 3 44 58 AM

Once we have logged in again, we can see how the hostname has been changed correctly.

Screen Shot 2022-11-24 at 3 46 30 AM

11 ◦ Check that all partitions are as indicated in the subject.

lsblk

Screen Shot 2022-11-24 at 3 52 17 AM

12 ◦ Check that sudo is installed.

which sudo

Screen Shot 2022-11-24 at 4 00 42 AM

Using which is not actually a good practice as not all packages are found in the paths where which searches. However, for the evaluation it is better as it is a simple and easy-to-learn command. For better use, we will use the following command:

dpkg -s sudo

Screen Shot 2022-11-24 at 4 02 13 AM

13 ◦ Add the new user to the sudo group.

sudo adduser name_user sudo

Screen Shot 2022-11-24 at 5 02 24 AM

We check that it is within the group.

Screen Shot 2022-11-24 at 5 02 39 AM

14 ◦ Show the application of the rules imposed for sudo by the subject.

Screen Shot 2022-11-24 at 5 12 02 AM

Screen Shot 2022-11-24 at 5 12 17 AM

15 ◦ Show that the path /var/log/sudo/ exists and contains at least one file, in this we should see a history of the commands used with sudo.

Screen Shot 2022-11-24 at 5 17 54 AM

Screen Shot 2022-11-24 at 5 19 07 AM

Run a command with sudo and check that the file is updated.

Screen Shot 2022-11-24 at 5 23 08 AM

Screen Shot 2022-11-24 at 5 23 21 AM

16 ◦ Check that the UFW program is installed on the virtual machine and check that it works correctly.

dpkg -s ufw

Screen Shot 2022-11-24 at 5 24 47 AM

sudo service ufw status

Screen Shot 2022-11-24 at 5 25 49 AM

17 ◦ List the active rules in UFW, if the bonus part is not done, the rule for port 4242 should only appear.

sudo ufw status numbered

Screen Shot 2022-11-24 at 5 27 50 AM

18 ◦ Create a new rule for port 8080. Verify that it has been added to the active rules and then you can delete it.

sudo ufw allow 8080 to create it.

Screen Shot 2022-11-24 at 5 31 35 AM

sudo ufw status numbered

Screen Shot 2022-11-24 at 5 31 59 AM

To delete the rule, we must use the command. sudo ufw delete num_rule

Screen Shot 2022-11-24 at 5 33 15 AM

We check that it has been deleted and we see the number of the next rule that needs to be deleted..

Screen Shot 2022-11-24 at 5 33 41 AM

Delete the new rule.

Screen Shot 2022-11-24 at 5 34 03 AM

We check that only the required rules in the subject remain.

Screen Shot 2022-11-24 at 5 34 11 AM

19 ◦ Check that the ssh service is installed on the virtual machine, that it works correctly, and that it only works on port 4242.

which ssh

Screen Shot 2022-11-24 at 5 37 25 AM

sudo service ssh status

Screen Shot 2022-11-24 at 5 40 34 AM

20 ◦ Use ssh to log in with the newly created user. Make sure that you cannot use ssh with the root user.

We try to connect over ssh with the root user but we do not have permission.

Screen Shot 2022-11-24 at 5 44 07 AM

We connect via ssh with the new user using the command ssh newuser@localhost -p 4242

Screen Shot 2022-11-24 at 5 48 06 AM

21 ◦ Modify the runtime of the script from 10 minutes to 1.

We run the following command to modify the crontab file sudo crontab -u root -e

Screen Shot 2022-11-24 at 6 30 57 AM

We modify the first parameter, instead of 10 we change it to 1.

Screen Shot 2022-11-24 at 6 31 44 AM

22 ◦ Translate English: Finally, make the script stop running when the server has started, but without modifying the script.

sudo /etc/init.d/cron stop

Screen Shot 2022-11-24 at 3 25 53 PM

Si queremos que vuelva a ejecutarse:

sudo /etc/init.d/cron start

Screen Shot 2022-11-24 at 3 27 38 PM

10- Tester 🆗

Check that you didn't forget anything! Own tester to check that the installation and configuration has been carried out successfully.

HERE

Screen Shot 2023-03-09 at 3 40 54 AM

Partner 👨🏻‍💻

This English version of the guide would not have been possible without the help of ElPatatin

◦ Linkedin: https://www.linkedin.com/in/cristope/

◦ Intra profile: https://profile.intra.42.fr/users/cpeset-c

Contact 📥

Contact me if you think I can improve the tutorial! It may help future students! 😁

◦ Email: [email protected]

◦ Linkedin: https://www.linkedin.com/in/gemartin99/

You might be interested!

- To see my progress in the common core 42 ↙️

HERE

- My profile on the intra 42 ↙️

HERE