After installing a Linux distribution in Oracle VirtualBox, you may be wondering how you can SSH from the host operating system into the virtual machine. After all, SSH is a great way to access and manage the system on command line.
Unfortunately, VirtualBox’s default configuration will not allow for this type of connection. Your virtual machine is most likely configured for NAT networking, but a bridged network interface is ideal for SSH connection between your guest and host operating systems.
In this tutorial, we will go over the step by step instructions to configure a VirtualBox virtual machine to accept incoming SSH connections. This will involve some configuration inside the VirtualBox settings, as well as ensuring that you have the SSH service properly installed and configured on the guest operating system.
In this tutorial you will learn:
- How to configure bridged network interface in VirtualBox
- How to install SSH, start SSH, and allow SSH through firewall
- Troubleshooting steps for SSH connection between host and guest
|Requirements, Conventions or Software Version Used
|Any Linux distro
|Oracle VirtualBox and OpenSSH Server
|Privileged access to your Linux system as root or via the
|# – requires given linux commands to be executed with root privileges either directly as a root user or by use of
$ – requires given linux commands to be executed as a regular non-privileged user
Configure Bridged Network on Virtual Machine
The first thing we need to do is set up the networking type of our virtual machine to bridged networking. This will allow for a connection between the host and guest operating system. It should not break your internet connectivity on the virutal machine. Follow the steps below to set it up.
- First, make sure that your virtual machine is powered off. Then, right click on the virtual machine and go into the Settings menu.
- Next, click on the Network tab, and configure the “Attached to” setting to be “Bridged Adapter.” Afterwards, you can click on OK to save your changes and exit this menu.
This part is done. Now you can continue on to the next section if you are still having trouble connecting from the host system to the virtual machine.
Configure SSH on Virtual Machine
Are you unable to connect even after configuring bridged networking? Most likely, it is because your SSH server is not properly setup on the guest operating system. Go through the troubleshooting steps below to make sure your virtual machine is accepting incoming connections for SSH.
- The first thing to make sure of is that you actually have SSH installed. it is not installed by default on every Linux distro.
Install SSH server on Debian based systems:
$ sudo apt install ssh
Install SSH server on Red Hat based systems:
$ sudo dnf install openssh-server
- Next, make sure that the SSH service is running by using the appropriate systemd command to start the SSH service for your Linux distro.
Start SSH server on Debian based systems:
$ sudo systemctl start ssh
Start SSH server on Red Hat based systems:
$ sudo systemctl start sshd
- Next, make sure that your system is allowing connections to SSH through the system firewall.
For systems with ufw (uncomplicated firewall), like Ubuntu:
$ sudo ufw allow ssh
For systems wth firewalld, like Red Hat based systems:
$ sudo firewall-cmd --zone=public --permanent --add-service=ssh $ sudo firewall-cmd --reload
For systems just using ordinary iptables:
$ sudo iptables -A INPUT -p tcp --dport ssh -j ACCEPT
- The next thing to make sure of is that you are not attempting to SSH into the root account on the guest operating system. By default, root logins for SSH are disabled. If you need to enable this, you will need to add this line to your
/etc/ssh/ssh_configconfiguration file in the virtual machine.
And then restart the service:
$ sudo systemctl restart ssh
In this tutorial, we saw how to enable SSH connectivity between a VirtualBox virtual machine and a host Linux operating system. To enable connectivity, we just need to configure the bridged network setting. If this doesn’t work, there is a high probability that the SSH service is not installed or just not properly configured on the guest operating system, for which we showed several troubleshooting steps.