Setting Up Ubuntu VM on macOS with VirtualBox
If you’re running macOS and want to experiment with Linux (for dev, learning, or server setup), VirtualBox is a free and reliable choice. Below, I’ll walk you through setting up Ubuntu 24.04 Server on VirtualBox, configuring networking, and enabling secure SSH access.
1. Install VirtualBox
- Download VirtualBox from the official website.
- Run the installer package and follow the steps to complete installation.
2. Create Your Ubuntu VM
-
Download the Ubuntu 24.04 Server ISO from Ubuntu’s site.
-
Open VirtualBox → New → create a new VM.
- Give it a name (e.g.,
Ubuntu-24.04
). - Point the ISO image to the downloaded Ubuntu ISO.
- Give it a name (e.g.,
-
Click Finish to finalize the VM creation.
3. Configure the VM
Before booting up, tweak these settings in VirtualBox:
-
User Interface: set Visual state →
Scaled
. -
System:
- Allocate CPU cores ≤ host CPU.
- Allocate memory ≤ host memory.
-
Network:
- Adapter 1 → Enabled
- Attached to:
Bridged Adapter
- Name:
en0: Wi-Fi
(Mac’s Wi-Fi) - Promiscuous Mode:
Deny
- MAC Address: generate a new one
- Cable Connected: ✅
4. Install and Enable SSH
Once the VM is up and running Ubuntu:
sudo apt install openssh-server
Back up the SSH config:
sudo cp /etc/ssh/sshd_config /etc/ssh/sshd_config.original
sudo chmod a-w /etc/ssh/sshd_config.original
Generate host keys (if missing):
sudo ssh-keygen -A
Restart SSH:
sudo systemctl restart ssh.service
5. Connect with SSH Keys
From inside the VM, get your VM’s IP:
sudo apt install net-tools
ifconfig
Look for inet
under enp0s3
→ that’s your VM’s IP (e.g., 10.10.10.52
).
From your Mac host, copy your public key:
ssh-copy-id -i ~/.ssh/your_public_key.pub <username>@<your-vm-ip>
Test login:
ssh <username>@<your-vm-ip>
Disable password login
Edit the config:
sudo nano /etc/ssh/sshd_config
Change:
PasswordAuthentication no
Restart SSH again:
sudo systemctl restart ssh.service
6. Assign a Static IP
To avoid your VM’s IP changing, configure it manually. Inside Ubuntu:
sudo nano /etc/netplan/static-ip-netcfg.yaml
Example:
network:
version: 2
ethernets:
enp0s3:
dhcp4: no
addresses: [10.10.10.52/24] # VM static IP
gateway4: 10.10.10.1
nameservers:
addresses: [8.8.8.8]
Apply config:
sudo netplan apply
✅ Done!
You now have:
- Ubuntu 24.04 Server running in a VirtualBox VM on macOS
- Bridged networking for direct access from your host
- Secure, key-based SSH access
- Static IP for stable connectivity
Perfect for dev environments, labs, or running lightweight services locally 🚀.
All rights reserved