Tech Quickie —  Connecting To A Virtual Machine From The Host Using SSH

March 31, 2019

Tech Quickie — Connecting To A Virtual Machine From The Host Using SSH

Photo by Kevin Ku on Unsplash

For a GUI-less server, the shared clipboard functionality of VirtualBox Guest Additions does not work, as a text-based server does not have a clipboard. Therefore, if you want to use copy and paste, you’ll have to connect to it using some kind of SSH client. is a special IP address known as the loopback address. When connecting to, you are in fact connecting to your own machine. The loopback address is typically used to test whether the network hardware (i.e. Network Interface Card) is functioning correctly. We’ll be using it to connect to a virtual machine running on our host.

When configured to NAT (Network Address Translation), VirtualBox will place the virtual machine inside of a private network (10.0.2.x).

In consequence, if we want to connect to a VM inside of the private network from the host’s network, we’ll have to set up port forwarding.

You can configure port forwarding by opening up the settings for the VM and then navigating to the network tab.

Because we are connecting to and from machines on the same host, they can’t both be using post 22 for SSH. Therefore, we set the port the host port to some arbitrary port (i.e. 2222).

It’s important to note that in order for this to work, your VM has to be able to accept incoming requests from SSH clients. If you haven’t already, install the proceeding package.

sudo apt-get install openssh-server

Finally, open up a command line on your host machine and connect to your VM using the same credentials you’d use to login.

ssh -p 2222 user@

Cory Maklin
_Sign in now to see your channels and recommendations!

Profile picture

Written by Cory Maklin Genius is making complex ideas simple, not making simple ideas complex - Albert Einstein You should follow them on Twitter