Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 39

JANUARY 26 2024

System administration Project

Gisela Hoxha
Project Overview:In this System Administration project, I undertook the challenge of
setting up a 64-bit Debian Linux server as a virtual machine using Oracle VM VirtualBox. The
project encompassed various tasks, including software installations, user management, sudo
privileges, storage expansion, LAMP stack deployment, web application installation, shell
scripting, cron job implementation, and Docker containerization exploration.
The project initiation involved installing essential software components such as the GNU C++
compiler, nmap, mdadm, gparted, and OpenSSH server. User management was carefully
executed, creating users with specific criteria and assigning sudo privileges. Security
configurations were implemented to ensure controlled access.
Storage expansion was a significant focus, involving the addition of three hard disks, creation of
logical volumes, and formatting using the ext4 filesystem. The deployment of the LAMP stack
included setting up Apache, PHP, and MariaDB, with a unique MariaDB root password.
The installation of a web application added complexity, showcasing adaptability in managing
diverse software. Shell scripting played a crucial role, with scripts created for tasks like sorting
music files based on length. The introduction of cron jobs automated periodic system
maintenance.
Exploring containerization with Docker, I created an image for a simple web app, gaining
insights into modern deployment practices. Adherence to industry best practices and thorough
documentation throughout the project highlighted proficient Linux system administration skills.

Task 1:Debian Virtual Machine Setup Report


Exercise Overview:

This exercise involves setting up a 64-bit Debian Linux virtual machine in VirtualBox with specific
configurations, installing the Xfce desktop environment, and configuring user accounts.

Step 1: VirtualBox Installation

Firstly, I download and installed VirtualBox from www.virtualbox.org.


Step 2: Creating a New Virtual Machine in VirtualBox

I opened VirtualBox and clicked on "New" the green button that is in the shape of a cross to create a
new virtual machine.

Next, I entered "debian-server" as the name.

I Selected "Linux" as the type and "Debian (64-bit)" as the version and clicked"Next."

Step 4: Allocate Memory

I Chose 2048 MB of memory (RAM).

Step 5: Create a Virtual Hard Disk

I Chose "Create a virtual hard disk now."

I Selected "VDI (VirtualBox Disk Image)" as the hard disk file type.

I Chose "Dynamically allocated" for storage and I set the size to 25 GB, I clicked “Next” and the Virtual
Machine is created now.
Step 6: Download Debian Netinst ISO

I download the small installation CD (netinst) for Debian 64-bit from this link
(https://www.debian.org/distrib/netinst).

Step 6: Attach Debian Netinst ISO

First of all, I selected the newly created virtual machine, then I clicked on "Settings” in the "Storage" tab.

In the "Controller: IDE" section, I clicked on the empty disk icon under "Attributes."

Then, I clicked on the disk icon next to "Optical Drive" and I chose the Debian Netinst ISO file that I
downloaded before.

Step 7: Debian Installation and starting the Virtual Machine

I selected the virtual machine and clicked "Start” then the Debian installer will be booted from the ISO.

Language and Location: I chose English and as a location I chose my current location.

Configure the Network: I set the hostname to "debian-server”, I left the domain empty.
Set Up Users and Passwords:

I set the root password to Admin@4321

Secondly, I created my username in the form "xy" (ghoxha according to my initials I replaced x with G
from my first letter of my given name, and y with Hoxha as my family name) and next I set the password
to "User4321."

Partition Disks:
I chose "Guided - use entire disk,” I selected the virtual hard disk that I created and then I chose "All files
in one partition."

Install the Base System:I chose "Software selection" and deselect everything except "SSH server."

Install the GRUB Boot Loader: I have chosen "Yes" to install GRUB.

The system now is finishing the installation.


Step 8: Post-Installation Configuration

Log In: Log in with the created my user credentials.

Install Xfce Desktop: I opened a terminal and run these commands:

sudo apt update

sudo apt install xfce4


Configure Automatic Login:

Reboot the system with this command:


sudo reboot
Start Xfce with this command:
startxfce4

TASK2:
Firstly, I opened a terminal in my Debian System.
Step 1: Update Package Lists
(Before installing any software, it's a good practice to update the package lists to ensure that I
have the latest information about available packages.) I updated with this command:
sudo apt update

Step 2: Install the GNU C++ Compiler (g++)


sudo apt install g++
Step 3: Install nmap
sudo apt install nmap
Step 5: Install mdadm
sudo apt install mdadm

Step 6: Install gparted


sudo apt install gparted
Step 7: Install OpenSSH Server
sudo apt install openssh-server

Step 8: Verify Installations


GNU C++ Compiler (g++): g++ --version

nmap: nmap –version


mdadm: mdadm --version
GParted: gparted –version
OpenSSH Server: ssh -V
Step 9: Test OpenSSH Server
ssh my_username@my_debian_ip(Debian_ip=127.0.0.1)

Task3
I added a new user named "test" with the adduser command.
sudo adduser test --home /home/test_home --shell /bin/sh

This command created a new user named "test" with the specified home directory
(/home/test_home) and shell (/bin/sh).
I set a password for the new user I entered the password "Test4321" as was required in the
question 3.
sudo chown test:test /home/test_home
I used this command to set the owner and group of the /home/test_home directory to "test."
So to adjust the ownership of their home directory.

TASK4
Step 1: Create an Alias for Shells (excluding bash, dash, sh)
I added the following lines to my shell configuration file (e.g., ~/.bashrc):
alias SHELLS='cat /etc/shells | grep -vE "bash|dash|sh"'
I have used this alias cat /etc/shells to list available shells and filters out bash, dash, and sh.
Step 2: Grant sudoer Privileges to "test" for "gparted" and "mdadm"
I edited the sudoers file using the visudo command:
sudo visudo
I added the following lines at the end of the sudoers file to grant "test" user privileges:
test ALL=(ALL:ALL) NOPASSWD: STORAGE_ADMIN

Step 3: Create an Alias for "gparted" and "mdadm"


I added the following lines to your shell configuration file (e.g., ~/.bashrc):
alias STORAGE_ADMIN='gparted,mdadm'
This alias groups "gparted" and "mdadm" commands together.
Step 4: Refresh the Shell Configuration
source ~/.bashrc

TASK5
Step 1: Add Three Hard Disks in VirtualBox
On VirtualBox I selected my virtual machine Debian-server.
On “Settings”, on the “Storage”, on the "Controller: SATA" section I clicked on the disk icon with
a plus sign to add a new hard disk. I repeated this process three times in order to create three
hard disks, each with a capacity of 250MB.
For each new hard disk, I was prompted to create a new hard disk or use an existing one. I
chose "Create a new disk" then the default VDI (VirtualBox Disk Image), I chose "Dynamically
allocated" and then I set the size 250MB of each virtual hard disk and now they are created.
Step 2: Start the Virtual Machine
Step 3: Partition and Format the Disks
I opened a terminal on my Debian system.
I used the lsblk command to list the available block devices.
Partition the Disks Using parted:
sudo parted /dev/sdb

Inside parted, create a new partition of size ~500 MB:


(parted) mkpart primary ext4 1MiB 500MB
Exit parted:
(parted) quit
I repeated the process for the other two disks (/dev/sdc and /dev/sdd), but I created in a 250
MB partition.

STEP4: Create Physical Volumes and Volume Group:


sudo pvcreate /dev/sdb /dev/sdc/dev/sdd
sudo vgcreate my_vg /dev/sdb /dev/sdc /dev/sdd
(I did this after installing the lvm2 package using the following command:
sudo apt install lvm2)
I Used the vgs command to verify the creation of the volume group:
sudo vgs

Step 5: Create Logical Volumes:


sudo lvcreate -L 500M -n lv_500 my_vg
sudo lvcreate -L 250M -n lv_250 my_vg

I used sudo lvs command to verify the creation of logical volumes


Step 6: Format the Logical Volumes
sudo mkfs.ext4 /dev/my_vg/lv_500
sudo mkfs.ext4 /dev/my_vg/lv_250
Step 7: Mount the Logical Volumes
I created mount points for the logical volumes:
sudo mkdir /mnt/lv_500
sudo mkdir /mnt/lv_250
Mount the logical volumes to the mount points:
sudo mount /dev/my_vg/lv_500 /mnt/lv_500
sudo mount /dev/my_vg/lv_250 /mnt/lv_250
Step 8: Verify and Test
I used the df -h command to verify that the logical volumes are mounted:
I Created files or directories in the mounted directories to test the functionality:
sudo touch /mnt/lv_500/test_file_500
sudo touch /mnt/lv_250/test_file_250
This completes the process of adding three hard disks, creating logical volumes,
formatting them with the ext4 filesystem, and mounting them.

TASK6
Step 1: Install Apache, PHP, and MariaDB
sudo apt update
sudo apt install apache2 php libapache2-mod-php mariadb-server php-mysql

During the MariaDB installation, it prompted me to set the root password. I set
it as "gisela123".

Step 2: Install phpMyAdmin


sudo apt install phpMyAdmin

During the installation, I chose the web server: apache2

I set the password: gisela123


After installation, phpMyAdmin is accessible at http://localhost/phpmyadmin.

Step 3: Configure Virtual Host


The directory for my virtual host:
mkdir ~/xy.com
The virtual host configuration file:
sudo nano /etc/apache2/sites-available/xy.com.conf

I added this configuration on it:


<VirtualHost *:80>
ServerAdmin webmaster@xy.com
ServerName www.xy.com
DocumentRoot /home/ghoxha/xy.com
<Directory /home/ghoxha/xy.com>
Options Indexes FollowSymLinks
AllowOverride All
Require all granted
</Directory>
ErrorLog ${APACHE_LOG_DIR}/xy.com_error.log
CustomLog ${APACHE_LOG_DIR}/xy.com_access.log combined
</VirtualHost>
I Enabled the virtual host and restart Apache by this command:
sudo a2ensite xy.com
sudo systemctl restart apache2

Step 4: Test the Setup


I created a test PHP file:
echo "<?php phpinfo(); ?>" > ~/xy.com/index.php
I accessed the virtual host with these commands:
http://www.xy.com
I accessed phpMyAdmin:
http://localhost/phpmyadmin
I checked Apache logs for any errors:
sudo tail -f /var/log/apache2/error.log
I verified the virtual host configuration:
sudo apache2ctl configtest
And it says Syntax OK.

TASK7
Installing Lime Survey (for student names starting with G-K):
I visited the official Joomla website https://www.limesurvey.org/ and I
downloaded from here the lasted version of it. I uziped the zip file of limesurvey
with this command : sudo unzip limesurvey6.4.3+240122.zip
Next I set permissions to it and put in the html file with this command: sudo chown -R www-
data:www-data /var/www/html/limesurvey.
Next, I opened my web browser and navigated:
http://your_server_ip/path/on/server/limesurvey.
TASK8
STEP 1: I used a text editor like nano to create the script with this command:
nano generate_wordlist.sh

Step2:I write this code on the file and saved it:


#!/bin/bash
# Check if the correct number of arguments is provided
if [ "$#" -ne 3 ]; then
echo "Usage: $0 <input_wordlist> <number_of_digits> <output_wordlist>"
exit 1
fi

input_wordlist="$1"
number_of_digits="$2"
output_wordlist="$3"

# Check if the input wordlist exists


if [ ! -f "$input_wordlist" ]; then
echo "Error: Input wordlist not found."
exit 1
fi
# Check if the number of digits is a positive integer
if ! [[ "$number_of_digits" =~ ^[1-9][0-9]*$ ]]; then
echo "Error: Number of digits must be a positive integer."
exit 1
fi
# Function to append digits to each word in the wordlist
append_digits() {
local word="$1"
local digits="$2"
for ((i=0; i<=9999; i++)); do
printf "%s%04d\n" "$word" "$i" >> "$output_wordlist"
done
}
# Main loop to process each word in the input wordlist
while IFS= read -r word; do
append_digits "$word" "$number_of_digits"
done < "$input_wordlist"
echo "Wordlist generation complete. Output saved to $output_wordlist."

Step3: I made the script executable by this command:


chmod +x generate_wordlist.sh
Step4: I created a input wordlist file with this command:
nano input_wordlist.txt
and I added John and password in my word list.
Step5:
Next, I was able to run the script using the following command:
./generate_wordlist.sh input_wordlist.txt 4 output_wordlist.txt
Finally, the generation of wordlist is complete and the output
is saved on output_worldlist.txt

TASK9
Step1: I opened the Crontab for Editing through this code:
crontab -e

Step2: I added the First Cron Entry (Midnight Cleanup):


0 0 * * * find /tmp/* -delete >> ~/.my_cron_log 2>&1
Step3: I added the Second Cron Entry (Wednesday Cleanup):
0 2 * * 3 find ~/Temporary/* -delete >> ~/.my_cron_log 2>&1
Step4: Add the Third Cron Entry (Sunday Cleanup):
30 3 * * 0 find ~/Temporary/* -delete >> ~/.my_cron_log 2>&1
I saved the changes and exited the editor.
Now, the cron jobs are set up, and they will run at the specified times.

Task10
Step 1: Install Docker with this code:
sudo apt update
sudo apt install docker.io
Step 2: Installing Flask
# Install Python3

sudo apt install -y python3

# Create a virtual environment

python3 -m venv venv

# Activate the virtual environment

source venv/bin/activate

# Install Flask using pip

pip3 install Flask

# Deactivate the virtual environment

Deactivate

Step4: Docker Installation through this code:


# Install required dependencies for Docker

sudo apt install -y \

apt-transport-https \

ca-certificates \

curl \

gnupg2 \

software-properties-common

# Download and add Docker's GPG key

curl -fsSL https://download.docker.com/linux/debian/gpg | sudo gpg --dearmor -o /usr/share/keyrings/docker-


archive-keyring.gpg

# Add Docker repository to the sources list


echo "deb [signed-by=/usr/share/keyrings/docker-archive-keyring.gpg] https://download.docker.com/linux/debian $
(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null

# Update the package list

sudo apt update

# Install Docker

sudo apt install -y docker-ce docker-ce-cli containerd.io

# Verify the Docker installation

sudo docker –version


Step5: Runing the Flask App through this code:
Python3 app.py

STEP6: CREATING DOCKER FILE


# Start from a lightweight Python and Flask image

FROM python:3.9-alpin
# Set the working directory inside the container

WORKDIR /app

# Copy the application files to the container

COPY . .

# Install Flask and its dependencies

RUN pip install --no-cache-dir -r requirements.txt

# Expose the port the app runs on

EXPOSE 5000

# Command to run the application

CMD ["python", "app.py"]

STEP7: Creating Requirements.txt file


# List of Python packages and their versions
Flask==2.0.2
Werkzeug==2.0.2
STEP8: Creating Docker Image
# Build a Docker image and tag it as "my-flask-app-image"
docker build -t my-flask-app-image .

STEP9: Running Docker Image


# Run the Docker image, mapping host port 5000 to container port 5000
docker run -p 5000:5000 my-flask-app-image

You might also like