DEV Community

Halton
Halton

Posted on

(basic) Provision VirtualBox Ubuntu VM Server on MacOS

This is when I open the VirtualBox Ubuntu Server Command UI, it's only the command.

by default
Username: vboxuser

update and install openssh-server

sudo apt update

sudo apt install openssh-server -y
Enter fullscreen mode Exit fullscreen mode

check if ssh is running

sudo systemctl status ssh
Enter fullscreen mode Exit fullscreen mode

it shows ssh not started, run below commands

sudo systemctl enable ssh

sudo systemctl start ssh
Enter fullscreen mode Exit fullscreen mode

confirm it’s listening

sudo ss -tlnp | grep ssh
Enter fullscreen mode Exit fullscreen mode

now, the configuration inside the VM linux is done


Now it's MacOS terminal turn

open local MacOS terminal run command, to list all the virtualbox VMs

VBoxManage list vms
Enter fullscreen mode Exit fullscreen mode

note that we are currently configuring the VM with name "ubuntu24-server2"


VBoxManage showvminfo "ubuntu24-server2" | grep -A3 "NIC 1"
Enter fullscreen mode Exit fullscreen mode

no ssh rules been added to this VM yet

check port 2222, it’s being occupied by another VM

lsof -iTCP:2222 -sTCP:LISTEN
Enter fullscreen mode Exit fullscreen mode

check port 2223, it’s free, let’s use 2223

lsof -iTCP:2223 -sTCP:LISTEN
Enter fullscreen mode Exit fullscreen mode

add rule to "ubuntu24-server2", but it failed, because "ubuntu24-server2"  is running now

VBoxManage modifyvm "ubuntu24-server2"  --natpf1 "ssh,tcp,,2223,,22"
Enter fullscreen mode Exit fullscreen mode

show running VMs

VBoxManage list runningvms
Enter fullscreen mode Exit fullscreen mode

shutdown the running "ubuntu24-server2"


 

VBoxManage controlvm "ubuntu24-server2" acpipowerbutton
Enter fullscreen mode Exit fullscreen mode

add rule to "ubuntu24-server2", again, it successed

VBoxManage modifyvm "ubuntu24-server2"  --natpf1 "ssh_dummy_name,tcp,,2223,,22"

VBoxManage showvminfo "ubuntu24-server2" | grep -A3 "NIC 1"
Enter fullscreen mode Exit fullscreen mode

start the "ubuntu24-server2" VM, the VM will be running on the backend

VBoxManage startvm "ubuntu24-server2" --type headless
Enter fullscreen mode Exit fullscreen mode

What it means: VBoxManage startvm → starts a VM from the command line (instead of clicking “Start” in the VirtualBox GUI).

--type headless → tells VirtualBox NOT to open the graphical console window.

The VM runs entirely in the background (no window, no dummy terminal)

using SSH to connect to the VM server

ssh -p 2223 <user>@127.0.0.1
Enter fullscreen mode Exit fullscreen mode

type yes and enter your username & password, you are all set

Top comments (0)