Before trying risky commands on a real VPS, practise on a virtual machine on your own computer. VirtualBox is a free type 2 hypervisor that runs on Windows, macOS (Intel and, in recent versions, Apple silicon) and Linux. This guide shows how to create a Linux VM in VirtualBox that behaves like a small VPS.
Before you start
- A computer with at least 8 GB RAM and 30 GB free disk.
- Hardware virtualization enabled; see enable VT-x/AMD-V.
- The VirtualBox installer from virtualbox.org and an Ubuntu Server ISO from ubuntu.com (ARM64 ISO on Apple silicon).
Install VirtualBox
Run the installer with default options. On Windows, if Hyper-V or WSL2 is enabled, VirtualBox still works but may be slower because it runs on top of Hyper-V.
Create the VM
- Click New, name it
lab-ubuntu, select the ISO and type Linux / Ubuntu (64-bit). Tick Skip Unattended Installation if you want to see the installer. - Hardware: 2048 MB RAM and 2 CPUs.
- Hard disk: create a 25 GB VDI, dynamically allocated.
- Finish, then start the VM and complete the Ubuntu Server installer. Tick Install OpenSSH server.
Choose networking
| Mode | Behaviour | Use for |
|---|---|---|
| NAT (default) | VM reaches internet; host reaches VM only via port forwards | Simple, works on any network |
| Bridged | VM gets its own IP on your LAN | Testing services from other devices |
| Host-only | Private network between host and VMs | Multi-VM labs |
SSH into the VM with NAT port forwarding
- Power off the VM, open Settings → Network → Adapter 1 → Advanced → Port Forwarding.
- Add a rule: host port
2222→ guest port22. - Start the VM and connect from your computer:
ssh -p 2222 youruser@127.0.0.1Now practise exactly as on a VPS: first steps on a new VPS, firewalls, web servers.
Use snapshots
Take a snapshot (Machine → Take Snapshot) before experiments. If something breaks, restore it in seconds. This is the main advantage of a lab VM.
Troubleshooting
- "VT-x is not available": enable virtualization in firmware, or another hypervisor is holding it.
- Only 32-bit options shown: virtualization extensions are disabled.
- SSH connection refused: OpenSSH not installed in the guest, or the port forward is missing.
Frequently asked questions
Is a VirtualBox VM the same as a VPS?
It runs the same OS and commands, but on your computer, behind your home network, without a public IP.
VirtualBox or WSL2?
WSL2 is great for Linux tools on Windows; a VirtualBox VM is closer to a real server with its own init system and network.
Can I move the VM to a real server?
Yes, export the disk and convert it; see convert disks to qcow2.
