SSH into a VirtualBox Linux guest from your host

In the recent years I have received some mails and questions as to how I SSH into a VirtualBox machine from my own pc.

Please be aware if you have the option to choose a bridged networking you can ssh into the VirtualBox without this guide. This guide is if you not want or not can use a bridged network.

The guide below assumes you already have a machine created if you have not done so then skim trough the guide and do the steps at the creation of the machine the result will be the same.

Also this guide was based on a Fedora virtual machine while it should work on any other Linux operating system the locations I use might be different if you use a non red hat based system.

(Please be aware that on certain machines VirtualBox slightly looks different, and for example on a mac you first have to create a host only network card in your VirtualBox settings)

Step 1: Stop your VirtualBox machine
Not much to explain here stop your virtual machine as the change would require a restart of the os.

Step 2: Go to the settings of your machine
Right click your virtual machine and choose “Settings” alternative click on the machine and press ctrl+s.

Step 3: Click on the network tab
Just have a look at the picture below if you are lost.

Step 4: Fill in the “Adapter 2” information
We will now make it so the os has a secondary network card that connects to your host only.

All you have to do is make Adapter 2 look as in the picture below, if you already use multiple network cards you can simply use Adapter 3 or 4 this is no problem at all.

Step 5: Start your machine
If you did step 4 correctly you can simply start your machine and wait for your linux host to have started.

Step 6: Find your ip information
In order to ssh into your machine we would need to find the ip information please run one of the following commands: “ifconfig” or “ip addr”.
$ ip addr

You should see then something like:

If you look at my example the ip address you need is the bottom one “” ofcourse this can differ for everyone and there is no way to know your setup so just try the ip addresses you will see and one will work :).

1. It has brought to my attention that if you install Linux with gnome that it might not work 100% correctly due to the network manager gnome uses.
2. In newer versions of Fedora your second network card is disabled by default you can fix this by doing “vim /etc/sysconfig/network-scripts/ifcfg-p7p1” (your file name can be different then mine but you can use what you see for name at 3 in the above picture) then once you are in the file change the “ONBOOT=no” to “ONBOOT=yes” and then restart your network sevices.

Step 7: Test you can SSH into your VirtualBox machine (from your real pc)
Go to your own Linux of Windows machine and start a terminal or Putty and do the following:
$ ssh [email protected]

Congratulations you can now ssh into your own virtualbox machine from you pc! 🙂 I told you it was easy.

**extra steps** (not necessarily needed)
I think it is not fun at all to find the ip address of your virtual-box unfortunately if you use DHCP you have no choose but to look up your ip every time again however you could simeply give your machine a static ip address and to make it even more easy give this IP a name in your host file.

Nice talking but how would you actually do this? Well have a look below.

Extra Step 1: Find your ip information and network card name.
If you already forgot your ip information then once again find it with “ifconfig” or “ip a”.
$ ifconfig

As was explained above you should see something like this:

In this case my network card is called “p7p1” and my ip address is “”.
(if you do not have ifconfig you can install it with: “sudo yum install net-tools”)

Extra Step 2: open you network card configuration file
$ vi /etc/sysconfig/network-scripts/ifcfg-p7p1

Again have a good look as the vi link above difference of course for you cards name.

Extra Step 3: Change your network card to static ip
In your configuration file add the following or change it (please use your ip information ofcourse).

My file looks as following:

Extra Step 4: Restart your network service
$ systemctl restart network.service

So now that you have a static ip address you can always ssh to that machine! easy enough but now lets make it little bit more easy and create a name for your ip address.

Extra Step 5: Open your host file (from your real pc not VirtualBox)
Fedora 22:
$ vi /etc/hosts

Windows 8.1 or 10:
notepad C:\Windows\System32\drivers\etc\hosts

Extra Step 6: add your ip and give it a name (from your real pc not VirtualBox) fedora22

My hosts file for example looks as following:

So that is it now you could for example ssh into you machine like this:
$ ssh root@fedora22
As always let me know if you see any mistakes or if you have any improvements I am glad to update guide!

Related posts

How to install MongoDB 4.0 in replication on Windows Server 2019

Sjir Bagmeijer

How to host an HTML5 website on AWS with S3 and CloudFront

Sjir Bagmeijer

How to use a VHD image file with VirtualBox

Sjir Bagmeijer