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
check if ssh is running
sudo systemctl status ssh
it shows ssh not started, run below commands
sudo systemctl enable ssh
sudo systemctl start ssh
confirm it’s listening
sudo ss -tlnp | grep ssh
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
note that we are currently configuring the VM with name "ubuntu24-server2"
VBoxManage showvminfo "ubuntu24-server2" | grep -A3 "NIC 1"
no ssh rules been added to this VM yet
check port 2222, it’s being occupied by another VM
lsof -iTCP:2222 -sTCP:LISTEN
check port 2223, it’s free, let’s use 2223
lsof -iTCP:2223 -sTCP:LISTEN
add rule to "ubuntu24-server2", but it failed, because "ubuntu24-server2" is running now
VBoxManage modifyvm "ubuntu24-server2" --natpf1 "ssh,tcp,,2223,,22"
show running VMs
VBoxManage list runningvms
shutdown the running "ubuntu24-server2"
VBoxManage controlvm "ubuntu24-server2" acpipowerbutton
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"
start the "ubuntu24-server2" VM, the VM will be running on the backend
VBoxManage startvm "ubuntu24-server2" --type headless
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
Top comments (0)