This project has been created as part of the 42 curriculum by aakhmeto.
Born2beRoot is a system administration project.
The goal is to create and configure a secure Linux virtual machine following strict rules. The project focuses on security, users, services, and system monitoring.
During the defense, the student must be able to explain every choice simply, as required in the subject.
- Create a virtual machine using VirtualBox.
- Install Debian (stable) without graphical interface.
- Configure disk partitions using LVM.
- Install and configure required services: sudo, SSH, UFW.
- Configure users, groups, and password policy.
- Add the monitoring script to cron.
- Connect to the virtual machine using SSH on port 4242.
- Log in with a user account (not root).
- The monitoring script runs automatically every 10 minutes.
- The project is done on a virtual machine.
- Virtualization allows running an operating system inside another system.
- It is useful for testing, security, isolation, and server administration.
The virtual machine is created and configured by the student.
The chosen operating system is Debian (stable).
- Stable and reliable
- Easy to use
- Good documentation
- AppArmor available by default
- Debian: simple, stable, good for learning
- Rocky Linux: enterprise-oriented, more complex
- apt: basic package manager
- aptitude: advanced interface with more features
- AppArmor is a security module
- It limits what programs can do
- It improves system security
AppArmor is enabled on this virtual machine.
-
A user with the student login exists
-
The user belongs to:
sudouser42
-
SSH connection as root is disabled
The password policy follows the subject rules:
-
Password expires every 30 days
-
Minimum 10 characters
-
At least:
- 1 uppercase letter
- 1 lowercase letter
- 1 number
-
No more than 3 identical characters in a row
-
Password must not contain the username
The student can explain why this policy is useful, with advantages and disadvantages.
-
sudois installed and configured -
Only authorized users can use sudo
-
Sudo rules:
- Maximum 3 password attempts
- Custom error message
- All sudo commands are logged in
/var/log/sudo/ - TTY mode enabled
- Restricted paths
The student can explain what sudo is, how it works, and why it is useful.
- UFW is installed and enabled
- The firewall is working correctly
- Only required ports are open
- Port 4242 is open for SSH
- A rule can be added and removed (example: port 8080)
The student can explain what a firewall is and why it is important.
- SSH service is installed and running
- SSH uses only port 4242
- SSH connection as root is disabled
- Login is done with a user account (password or key)
The student can explain what SSH is and its purpose.
A script called monitoring.sh is created.
- It displays system information using
wall - It runs every 10 minutes using cron
Displayed information includes:
- OS and kernel
- CPU and RAM usage
- Disk usage
- Last reboot
- LVM status
- Active connections
- Number of users
- IP and MAC address
- Number of sudo commands
The student can explain:
- How the script works
- What
cronis - How the script is scheduled
The script can be stopped without modifying the script itself, as required in the subject.
- Disk partitions follow the subject example
- LVM is used to manage logical volumes
LVM allows flexible disk management and easier resizing.
- AppArmor is enabled
- SSH root login is disabled
- Firewall is active
- A main user with the student login exists
- Groups:
sudo,user42
Below is a full defense checklist with commands and links.
- Go through the full checklist and confirm everything works.
- Shut down the VM.
- Get the SHA1 signature of the VM disk:
sha1sum <name>.vdi. - Put the signature into
signature.txtat repo root. - Push and verify the repo.
- Finalize and book the defense.
- Check that
signature.txtexists in the root of the cloned repo. - Ensure that the SHA1 in
signature.txtmatches the.vdifile of the VM being evaluated. Example diff:diff signature.txt <(sha1sum <name>.vdi | awk '{print $1}') - As a precaution, make a copy of the submitted VM image in another directory and run the evaluation on the copy.
- Make sure no snapshots are used (check in VirtualBox and in files).
The student must explain in simple words:
- How a virtual machine works. Links: https://github.com/ayoub0x1/born2beroot?tab=readme-ov-file https://42-cursus.gitbook.io/guide/1-rank-01/born2beroot/whats-a-virtual-machine
- Why they chose this OS. Links: https://www.debian.org/ https://www.debian.org/releases/
- Main differences between Rocky and Debian.
- The purpose of virtual machines.
- If Debian was chosen:
- difference between
aptitudeandapt - what AppArmor is
Check AppArmor status:
/usr/sbin/aa-statusLink: https://42-cursus.gitbook.io/guide/1-rank-01/born2beroot/install-your-virtual-machine
- difference between
- During defense the script must print info every 10 minutes. It will be checked later in detail.
- Ensure no graphical interface is installed (no X.org, Wayland, etc.).
- At boot you should be asked for a password.
- Login must be done with a non-root user (student login).
- Check password policy for the user:
chage -l <login> - Check UFW is running:
sudo ufw status - Check SSH is running:
systemctl status sshorservice ssh status - Check OS is Debian or Rocky:
cat /etc/os-releaseorhead -n 2 /etc/os-release
-
Student login user exists and is in groups
sudoanduser42:id <login>groups <login>getent group sudogetent group user42 -
Password policy rules are correctly set (subject rules):
minlen=10ucredit=-1dcredit=-1lcredit=-1maxrepeat=3reject_usernamedifok=7enforce_for_root
2.1 Create a new user and assign a password that matches the policy:
sudo adduser testusersudo passwd testuserid testusergroups testusersudo chage -l testuser
2.2 Student must explain how the password policy was configured. Files to show:
/etc/login.defsPASS_MAX_DAYS 30PASS_MIN_DAYS 2PASS_WARN_AGE 7
/etc/pam.d/common-password- After
retry=3, add the password rules listed above
- After
Also show that libpam-pwquality is installed:
dpkg -l | grep libpam-pwquality
- Create a group named
evaluatingand add the new user to it:
sudo addgroup evaluatingsudo adduser testuser evaluatinggetent group evaluating
- Student must explain advantages and disadvantages of this policy.
- Check hostname format is
login42:hostname - Change hostname to your login, reboot, check it changed:
sudo hostnamectl set-hostname <yourlogin>42sudo reboothostname - Restore original hostname.
- Show partitions and compare to subject example:
lsblk - Student must explain what LVM is and why it is used.
- Check sudo is installed:
dpkg -l | grep sudo - Show how to add a user to
sudogroup:sudo adduser <user> sudoorsudo usermod -aG sudo <user> - Show sudo rules in
/etc/sudoers.d/:
passwd_tries=3badpass_message="<custom-message>"log_inputlog_outputiolog_dir="/var/log/sudo"requirettysecure_path="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/snap/bin"
- Student explains what sudo is and why it is useful.
- Check
/var/log/sudo/exists and contains log files:ls /var/log/sudo - Run a sudo command and check logs updated.
- Check firewall is installed and running:
sudo ufw statusorsudo firewall-cmd --state - Show active rules. Port
4242must be open for SSH. - Add a rule for port
8080:sudo ufw allow 8080 - Check rule was added:
sudo ufw status numbered - Remove the rule:
sudo ufw delete allow 8080
- Check SSH service is installed and running:
systemctl status sshorservice ssh status - Check SSH config:
/etc/ssh/sshd_configPort 4242PermitRootLogin no
- Student explains what SSH is and why it is used.
- Check only port
4242is used:ss -tuln - SSH login with new user:
ssh <user>@localhost -p 4242 - Ensure root SSH login is disabled.
If SSH key error happens:
- Remove the old key entry in
~/.ssh/known_hostsfor[localhost]:4242and retry.
- Student explains how
monitoring.shworks (show the code). - Student explains what cron is.
- Show cron entry for root:
sudo crontab -u root -eExample line:*/10 * * * * sh /path/to/monitoring.sh - After checking, make it run every minute.
- Run something like
yes > /dev/null &to test dynamic values, thenkill %1. - Stop the script without modifying it (comment out cron line).
- Reboot and confirm:
- script is still in the same place
- permissions are unchanged
- script was not modified
Script must display:
- OS architecture and kernel version
- Number of physical CPUs
- Number of virtual CPUs
- Available RAM and % used
- Available disk space and % used
- CPU usage %
- Last reboot date and time
- LVM status
- Number of active connections
- Number of users
- IP and MAC address
- Number of sudo commands
Bonus points are awarded for extra services. Typical bonus setup:
-
Disk partitions setup (LVM) is worth 2 points. Command:
lsblk -
WordPress stack (2 points): lighttpd + MariaDB + PHP. Install and configure:
-
sudo apt install lighttpd -
sudo ufw allow 80 -
sudo apt install wget zip -
cd /var/www -
sudo wget https://wordpress.org/latest.zip -
sudo unzip latest.zip -
sudo mv html/ html_old/ -
sudo mv wordpress/ html -
sudo chmod -R 755 htmlMariaDB:
-
sudo apt install mariadb-server -
dpkg -l | grep mariadb-server -
sudo mariadb_secure_installation -
mariadb -
CREATE DATABASE wp_database; -
CREATE USER 'wp_user'@'localhost' IDENTIFIED BY 'strong_password'; -
GRANT ALL PRIVILEGES ON wp_database.* TO 'wp_user'@'localhost'; -
FLUSH PRIVILEGES; -
exit -
mariadb -u wp_user -p -
SHOW DATABASES;PHP:
-
sudo apt install php-cgi php-mysql -
dpkg -l | grep php -
cd /var/www/html -
cp wp-config-sample.php wp-config.php -
Edit
wp-config.phpwith DB name, user, password Example reference: https://github.com/Vikingu-del/Born2beRoot/raw/main/photos/bonus/underlinedtochange.png -
sudo lighty-enable-mod fastcgi -
sudo lighty-enable-mod fastcgi-php -
sudo service lighttpd force-reloadStudent should explain:
-
Lighttpd is a lightweight web server.
-
WordPress is a PHP app.
-
MariaDB stores the data.
-
Free-choice service (1 point). Example: FTP (vsftpd).
Install and configure FTP:
-
sudo apt install vsftpd -
dpkg -l | grep vsftpd -
sudo ufw allow 21 -
sudo nano /etc/vsftpd.conf- Enable:
write_enable=YES - Enable:
chroot_local_user=YES
- Enable:
-
Create FTP directories:
sudo mkdir /home/<user>/ftpsudo mkdir /home/<user>/ftp/filessudo chown nobody:nogroup /home/<user>/ftpsudo chmod a-w /home/<user>/ftp
-
In
/etc/vsftpd.confadd:user_sub_token=$USERlocal_root=/home/$USER/ftp
-
Edit user list:
sudo nano /etc/vsftpd.userlistsudo nano /etc/vsftpd.userlist_deny- Set in config:
userlist_enable=YESuserlist_file=/etc/vsftpd.userlistuserlist_deny=NO
-
Check service and port:
sudo systemctl status vsftpdsudo ss -tuln | grep :21
Test FTP:
-
ftp <ip-address> -
put text.txt
Student must explain what the service does and why it is useful.
Official questions list: https://42-cursus.gitbook.io/guide/1-rank-01/born2beroot/p2p-evaluation-questions