Skip to main content

Lab 1.2 - Installing an Ubuntu 24.04 VM with Oracle VirtualBox Hypervisor

Lab Objectives​

By the end of this lab, you will be able to:

  • Install and configure Oracle VirtualBox
  • Create an Ubuntu 24.04 virtual machine
  • Configure network adapters (NAT and Host-only)
  • Install and configure SSH
  • Connect to the VM from Windows via SSH
  • Create users and configure sudo
  • Customize the environment with .bashrc

Estimated Duration​

1-2 hours

Prerequisites​

  • Oracle VirtualBox installed on your machine
  • Ubuntu 24.04 Desktop ISO image
  • At least 20 GB of free disk space
  • 4 GB of available RAM (8 GB recommended)

Part 1: Installing the Ubuntu 24.04 VM​

Step 1: Download Ubuntu 24.04​

  1. Download the Ubuntu 24.04 ISO from the official site:

Step 2: Open Oracle VirtualBox​

  1. Launch Oracle VirtualBox on your machine

Step 3: Create a new virtual machine​

  1. Click on NEW

  2. Fill out the form:

    • Name: Ubuntu 24.04 (or a name of your choice)
    • Type: Linux
    • Version: Ubuntu (64-bit)
  3. Click on NEXT

Step 4: Allocate memory​

  1. Reserve the necessary memory space:

    • Minimum recommended: 2048 MB (2 GB)
    • Recommended: 4096 MB (4 GB) or more
  2. Click on NEXT

Step 5: Create the virtual hard disk​

  1. Choose "Create a virtual hard disk now"

  2. Click on CREATE

  3. Choose VDI (VirtualBox Disk Image)

  4. Click on NEXT

  5. Choose Dynamically allocated

  6. Click on NEXT

  7. Allocate the necessary disk space:

    • Minimum: 20 GB
    • Recommended: 30-40 GB
  8. Click on CREATE

Step 6: Configure the ISO​

  1. Select your virtual machine from the list

  2. Click on Settings

  3. Go to Storage

  4. Under Controller: IDE, click on the empty disk icon

  5. Click on the disk icon to the right of "Optical Drive"

  6. Choose "Choose a disk file..."

  7. Select your downloaded Ubuntu 24.04 ISO file

  8. Click on OK

Step 7: Start the installation​

  1. Click on Start to launch the VM

  2. Follow the Ubuntu installation:

    • Choose your language
    • Choose "Normal installation"
    • Do not enable Ubuntu Pro (uncheck if prompted)
  3. Fill out the user creation form:

    • Username: student (or your choice)
    • Password: Choose a secure password
    • Machine name: Leave default or customize
  4. Review the summary before installation

  5. Click on Install Now

  6. Wait for the installation to complete (15-30 minutes)

  7. Restart the virtual machine when prompted


Part 2: Configuring Network Adapters​

Step 1: Access network settings​

  1. Shut down the VM if it is running

  2. Select your virtual machine

  3. Click on Settings

  4. Go to Network

Step 2: Configure the first network adapter (NAT)​

  1. Under Adapter 1, ensure "Enable Network Adapter" is checked

  2. Choose NAT from the "Attached to" dropdown menu

  3. This adapter will allow the VM to access the Internet

Step 3: Add a second network adapter (Host-only)​

  1. Go to the Adapter 2 tab

  2. Check "Enable Network Adapter"

  3. Choose Host-only Adapter from the "Attached to" dropdown menu

  4. This adapter will allow communication between your host machine and the VM

  5. Click on OK

Step 4: Verify network adapters​

  1. Start your virtual machine

  2. Log in with your user (student)

  3. Open a terminal

  4. Verify the presence of the two network adapters:

ip a

You should see two network interfaces:

  • enp0s3 (or similar) - NAT Adapter (first adapter)
  • enp0s8 (or similar) - Host-only Adapter (second adapter)
  1. Note the IP address of the second adapter (enp0s8):
    • Look for the line starting with inet
    • Example: inet 192.168.177.5/24
    • Note this IP address (you will need it for SSH)

Part 3: Installing and Configuring SSH​

Step 1: Switch to superuser mode​

su
# Enter the root password (or your user password if configured)

Step 2: Verify your identity​

whoami
# Should display: root

pwd
# Displays the current directory

Step 3: Update packages​

apt update

Step 4: Install OpenSSH Server​

apt install openssh-server -y

Step 5: Check SSH status​

systemctl status ssh
# To exit, press :q

Step 6: Enable and start SSH​

systemctl enable ssh
systemctl start ssh
systemctl status ssh
# To exit, press :q

Step 7: Clear the screen​

clear

Part 4: SSH Connection from Windows​

Step 1: Open Windows terminal​

  1. Press Windows + R
  2. Type cmd and press Enter
    • Or open PowerShell

Step 2: Connect via SSH​

ssh student@IP-you-noted

Example:

ssh student@192.168.177.5

Step 3: Accept the SSH key​

  1. On first connection, you will see:

    The authenticity of host '192.168.177.5' can't be established.
    Are you sure you want to continue connecting (yes/no)?
  2. Type yes and press Enter

  3. Enter the password for the student user

  4. You are now connected to your Ubuntu VM from Windows!


Part 5: Exploring Basic Commands​

Exercise 1: Changing User​

# You are logged in as 'student'
whoami
# Should display: student

# Switch to superuser
sudo -s
whoami
# Should display: root

# Verify identity
id
# Displays UID, GID, and groups

# Switch back to student user
exit
# or
su - student

whoami
# Should display: student

pwd
# Displays the current directory

id
# Displays information for the student user

Exercise 2: Creating Directories​

# Switch to superuser
sudo -s

# Create a test directory
mkdir test
cd test
whoami
# Should display: root

pwd
# Should display: /root/test

# Switch back to student user
su - student

pwd
# Should display: /home/student

Part 6: Creating and Managing Users​

Exercise 1: Create a new user​

# Switch to superuser
sudo -s

# Create a new user
sudo adduser superfun
# Follow the prompts (password, full name, etc.)

# Log in with the new user
su - superfun

whoami
# Should display: superfun

Exercise 2: Test permissions​

# Try to execute a command requiring privileges
sudo apt update
# Should fail: superfun is not in the sudo group

sudo install curl
# Should fail

sudo ls /root
# Should fail

Exercise 3: Add user to sudo group​

# Switch back to root
sudo -s
# or
exit

whoami
# Should display: root

# Add superfun to the sudo group
sudo usermod -aG sudo superfun

# Reconnect with superfun
su - superfun

# Now sudo commands should work
sudo ls /root
# Should work

sudo apt install curl
# Should work

Part 7: Customizing the Environment with .bashrc​

Step 1: Install customization tools​

sudo apt update
sudo apt install figlet toilet -y

Step 2: Test the tools​

figlet "Welcome!"
toilet -f mono12 -F metal "Hello Hacker!"

Step 3: Add messages to .bashrc​

# Add a welcome message with figlet
echo 'figlet "Welcome!"' >> ~/.bashrc

# Add a message with toilet
echo 'toilet -f mono12 -F metal "Hello Hacker!"' >> ~/.bashrc

Step 4: Test the customization​

# Exit the session
exit

# Reconnect
su - superfun

# The messages should display automatically

Step 5: Modify the .bashrc​

# Open the .bashrc file with nano
sudo nano ~/.bashrc

# Edit the messages at the end of the document
# Use the arrows to navigate
# Modify the text as desired

# To save and exit:
# Press Ctrl + X
# Press Y to confirm
# Press Enter

Explanation of ~/.bashrc​

~/.bashrc is a user-specific configuration file for the bash shell.

  • It is executed each time an interactive terminal is opened (e.g., when you open a new graphical terminal)
  • It contains aliases, environment variables, prompt colors, functions, etc.
  • The ~ means "the user's home directory" (/home/superfun/.bashrc for example)
  • Everything you add there is automatically applied to each new terminal for that user only

Additional Exercise: Navigating /home​

# Go to the /home directory
cd /home

# List the contents
ls

# You should see the directories of created users
# For example: student, superfun

Summary of Important Commands​

System Commands​

CommandDescription
whoamiDisplays the current user's name
pwdDisplays the current directory
idDisplays the user's UID, GID, and groups
suSwitches user (to root by default)
su - userSwitches to a specific user
sudo -sSwitches to superuser mode
exitExits the current session

Network Commands​

CommandDescription
ip aDisplays all network interfaces and their IP addresses
systemctl status sshChecks the status of the SSH service
systemctl enable sshEnables SSH at startup
systemctl start sshStarts the SSH service

User Commands​

CommandDescription
adduser usernameCreates a new user
usermod -aG sudo userAdds a user to the sudo group
cd /homeGoes to the directory containing users' home directories

Customization Commands​

CommandDescription
nano ~/.bashrcOpens the .bashrc file for editing
echo 'command' >> ~/.bashrcAdds a line to the end of the .bashrc

Final Verification​

Ensure you have successfully:

  • Installed Ubuntu 24.04 in VirtualBox
  • Configured two network adapters (NAT and Host-only)
  • Installed and enabled SSH
  • Connected to the VM from Windows via SSH
  • Created a new user
  • Added a user to the sudo group
  • Customized the .bashrc with figlet and toilet
  • Understood the difference between su, sudo -s, and su - user

Next Steps​

  • Lab 1.1: Installation and First Use (if not yet done)
  • Module 2: Linux System Architecture
  • Module 3: File System

Lab created on: December 2024