How to SSH Into a VirtualBox Ubuntu Server

Virtual machines provide engineers and administrators with a good platform for testing software, setting up IT environments and maximizing the use of server hardware resources.


VirtualBox is one of the most popular virtualization software on the market today. It’s open source and packed with lots of nice features. Let’s take a look at how to SSH into an Ubuntu server or desktop running in VirtualBox.


Step 1: Install SSH on the virtual machine

SSH is one of the main ways to manage and interact with Linux servers that don’t come with a GUI. Of course you can also use SSH in full desktop environments.

In order to access another PC using SSH, the system must be running an SSH server and its service should be enabled. In addition, the PC from which you initiate the SSH connection must have an SSH client.

This guide shows the process with Ubuntu Desktop as the host operating system and Ubuntu Server as the guest operating system in VirtualBox, but the procedure is basically the same regardless of the operating system used. If you don’t have a guest operating system, you can install Ubuntu as a guest operating system on VirtualBox.

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

Install SSH on the virtual machine with the following command:

sudo apt install openssh-server

Your SSH server will start automatically. You can check its status with the following command:

sudo systemctl status ssh

If the SSH port is not enabled on your firewall, use the UFW tool to enable the SSH port.

Step 2: Configure VirtualBox Network

By default, VirtualBox creates a Network Address Translation (NAT) adapter for your virtual machines. This allows your virtual machine to access the internet, but prevents other devices from accessing it via SSH.

To configure networking, you need to use VirtualBox port forwarding and the default NAT adapter your VM is connected to. Note that VirtualBox offers many other network configuration options, e.g. B. a bridged adapter that you can use to SSH into guest operating systems, but that’s a topic for another day.

Right-click the VM you want to SSH into and click the settings cog to open the settings window. Alternatively, you can also use the key combination: Ctrl + S. Then click on the network Possibility.

Click on that Progressive option and select port forwarding. VirtualBox will show you a screen to configure your port forwarding rules.

Add a port forwarding rule

Click on that plus (+) icon under the Port Forwarding Rules Side.

Give your rule a meaningful name (e.g. “SSH port forwarding”). Use the standard protocol, ie TCP. The host IP will be 127.0.0.1 or simply local host and use 2222 as the host port.

Get the IP address of your Ubuntu server running in VirtualBox and enter it in the Guest IP Input box. In this case, my guest OS’s IP address is 10.0.2.13. Use 22 as the guest port.

Finally, press the OK Button.

You may need to restart your virtual machine for the changes to take effect.

Step 3: Start your SSH session

From the terminal in your main operating system, run the SSH command in the following format: ssh -p 2222 [email protected]. For example:

ssh -p 2222 mwizak@127.0.0.1

Please note that mwizakis the login username for the virtual machine in this case. Finally, enter the password for the guest operating system user when prompted to initialize the connection.

Don’t forget to secure the SSH connection!

SSH is an easy way to connect to remote servers or computers, and now you can use it to access your VirtualBox guest operating systems.

As secure as SSH is, it’s also a prime target for hackers looking to gain access to your systems. So make sure you follow security best practices when using SSH.

Leave a Reply

Your email address will not be published. Required fields are marked *