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
- Download the Ubuntu 24.04 ISO from the official site:
- URL: https://ubuntu.com/download/desktop
- Choose the Desktop version (64-bit)
Step 2: Open Oracle VirtualBox
- Launch Oracle VirtualBox on your machine
Step 3: Create a new virtual machine
-
Click on NEW
-
Fill out the form:
- Name: Ubuntu 24.04 (or a name of your choice)
- Type: Linux
- Version: Ubuntu (64-bit)
-
Click on NEXT
Step 4: Allocate memory
-
Reserve the necessary memory space:
- Minimum recommended: 2048 MB (2 GB)
- Recommended: 4096 MB (4 GB) or more
-
Click on NEXT
Step 5: Create the virtual hard disk
-
Choose "Create a virtual hard disk now"
-
Click on CREATE
-
Choose VDI (VirtualBox Disk Image)
-
Click on NEXT
-
Choose Dynamically allocated
-
Click on NEXT
-
Allocate the necessary disk space:
- Minimum: 20 GB
- Recommended: 30-40 GB
-
Click on CREATE
Step 6: Configure the ISO
-
Select your virtual machine from the list
-
Click on Settings
-
Go to Storage
-
Under Controller: IDE, click on the empty disk icon
-
Click on the disk icon to the right of "Optical Drive"
-
Choose "Choose a disk file..."
-
Select your downloaded Ubuntu 24.04 ISO file
-
Click on OK
Step 7: Start the installation
-
Click on Start to launch the VM
-
Follow the Ubuntu installation:
- Choose your language
- Choose "Normal installation"
- Do not enable Ubuntu Pro (uncheck if prompted)
-
Fill out the user creation form:
- Username:
student(or your choice) - Password: Choose a secure password
- Machine name: Leave default or customize
- Username:
-
Review the summary before installation
-
Click on Install Now
-
Wait for the installation to complete (15-30 minutes)
-
Restart the virtual machine when prompted
Part 2: Configuring Network Adapters
Step 1: Access network settings
-
Shut down the VM if it is running
-
Select your virtual machine
-
Click on Settings
-
Go to Network
Step 2: Configure the first network adapter (NAT)
-
Under Adapter 1, ensure "Enable Network Adapter" is checked
-
Choose NAT from the "Attached to" dropdown menu
-
This adapter will allow the VM to access the Internet
Step 3: Add a second network adapter (Host-only)
-
Go to the Adapter 2 tab
-
Check "Enable Network Adapter"
-
Choose Host-only Adapter from the "Attached to" dropdown menu
-
This adapter will allow communication between your host machine and the VM
-
Click on OK
Step 4: Verify network adapters
-
Start your virtual machine
-
Log in with your user (
student) -
Open a terminal
-
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)
- 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)
- Look for the line starting with
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
- Press
Windows + R - Type
cmdand 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
-
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)? -
Type yes and press Enter
-
Enter the password for the
studentuser -
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/.bashrcfor 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
| Command | Description |
|---|---|
whoami | Displays the current user's name |
pwd | Displays the current directory |
id | Displays the user's UID, GID, and groups |
su | Switches user (to root by default) |
su - user | Switches to a specific user |
sudo -s | Switches to superuser mode |
exit | Exits the current session |
Network Commands
| Command | Description |
|---|---|
ip a | Displays all network interfaces and their IP addresses |
systemctl status ssh | Checks the status of the SSH service |
systemctl enable ssh | Enables SSH at startup |
systemctl start ssh | Starts the SSH service |
User Commands
| Command | Description |
|---|---|
adduser username | Creates a new user |
usermod -aG sudo user | Adds a user to the sudo group |
cd /home | Goes to the directory containing users' home directories |
Customization Commands
| Command | Description |
|---|---|
nano ~/.bashrc | Opens the .bashrc file for editing |
echo 'command' >> ~/.bashrc | Adds 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, andsu - 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