VirtualBox is one of the most popular virtualization software on the market today.

It’s open source and is packed with lots of nice features.

Let’s take a look at how to SSH into an Ubuntu server or desktop running in VirtualBox.

set up ssh on ubuntu virtualbox (1)

Of course, you could use SSH on full-blown desktop environments too.

Also, the PC you are initiating the SSH connection from needs to have an SSH client.

Launch VirtualBox and then start your Ubuntu virtual machine from the GUI.

ssh service status output on ubuntu

On the virtual machine, install SSH using the command:

Your SSH server will start up automatically.

This allows your virtual machine to dive into the internet but prevents other devices from accessing it via SSH.

Right-punch the VM you want to SSH into and hit the Setting cog to launch the prefs window.

selecting port forwarding rules in VirtualBox

Alternatively, you might also use the keyboard shortcut:Ctrl + S. Next, select theNetworkoption.

punch theAdvancedoption and selectPort Forwarding.

VirtualBox will present you with a screen to configure your port forwarding rules.

configure port forwarding in virtual box

Add a Port Forwarding Rule

punch thePlus(+) icon under thePort Forwarding Rulespage.

Give your rule a meaningful name (for example “SSH port forwarding”).

Use the default protocol i.e.TCP.

The host IP will be127.0.0.1or simplylocalhostand use 2222 as theHost Port.

Get the IP address of your Ubuntu serverrunning inside VirtualBox and enter it in theGuest IPinput box.

In this case, my guest OS IP address is 10.0.2.13.

Use 22 as the guest port.

Finally, press theOkbutton.

You might need to reboot your virtual machine for the changes to take effect.

For example:

kindly note thatmwizak, in this case, is the login username for the virtual machine.

Finally, enter the password for the guest OS user when prompted to initialize the connection.

Don’t Forget to Secure the SSH Connection!

So check that you follow the best security practices when using SSH.