Setup SSH connection to your Ubuntu VM of VirtualBox (MacOS)

Rocky Chen
Nov 15, 2020

I installed an Ubuntu OS on VirtualBox in my MacOS which is a minimal server version. So I decide to connect to it via SSH with my terminal instead of the VM console.

Here is what I did:

1. Setup SSH server on the Ubuntu VM

1.1 Install SSH server

sudo apt-get install openssh-server

1.2 Enable the SSH service

sudo systemctl enable ssh

1.3 Start the SSH service

sudo systemctl start ssh

1.4 Verify the SSH connection locally

ssh user_name@localhost

It should be able to connect itself via SSH connection if everything is correct.

2. Setup VirtualBox

2.1 Power off the Ubuntu VM.

2.2 Setup port forwarding in the VM Network settings.

2.3 Start the Ubuntu VM.

3. Connect to the Ubuntu VM from my MacOS

Connect to the VM via the port set for forwarding:

ssh user_name@127.0.0.1 -p 2222

Done.

--

--

Rocky Chen

SRE | Cloud Engineer | AWS Certified Solutions Architect – Professional