VirtualBox: Connect to Guest from Host by SSH (E.g. Putty)
V irtualBox is a general-purpose full virtualizer for x86 hardware, targeted at server, desktop and embedded use. You can install and run quite a few different OS by VirtualBox. For example, you can install Fedora with VirtualBox, then install SSHD service within Fedora OS. By some simple Network configuration, you can connect to Fedora OS from your Host Machine OS such as Windows 10. This article is to tell how to do this step by step.
Assuming you already installed VirtualBox and have one Virtual Image with Fedora OS installed.
Install OpenSSH Server on Fedora
Depends on how you installed Fedora, you can open one terminal and search openssh package by yum command. For example,
In the result list, we got what we want to install: openssh-server.x86_64 then we run install command to install it:
If you already installed it, you will get the completely same output as above. Otherwise, it will show how much size of file to download and ask you if go forward to install it. Click Y to install.
Start OpenSSH Server on Fedora
After installation, you can start the openssh server and also make it start automatically at the boot time. See more details on Fedora document Starting an OpenSSH Server.
When OpenSSH Daemon started, you can see its status by below command:
Configure VirtualBox Network for Fedora VM
Open VirtualBox Manager and go to the tab of Fedora VM. Click Settings -> Network -> Adapter 1, then click “Port Forwarding” to open “Port Forwarding Ruels”
You can click the green icon with + sign to add one new rule for port forwarding. Then, fill in Host IP, Host Port, Guest IP, and Guest Port .
In Windows, you can get Host IP address by ipconfig command and in Fedora you can use ifconfig or ip address. It’s enough to use local IP address, no need to use global IP address.
For Guest IP of Fedora VM, you can use value of inet of interface enp0s8 which is also assgined one local IP address. (Note: you can check all interfaces and their IP addresses by ip address , in case it’s not enp0s8 in your VM)
When you finish, Click OK to save and close the dialog.
Note: from Host, you cannot ping or connect to the Guest IP address directly. That’s why Port Forwarding is required.
Connect to Guest OS by SSH Client from Host OS
As we forwarded Host port (1022) to Guest port (22), so we can connect to Host port by SSH client: (in fact, it will connect to Guest port 22)
If you use Putty, then just fill Host Name (or IP address) and Port accordingly and Open the connection: (See article for more information about PuTTY Configuration)
How to use Putty to connect to a virtual machine?
On running ifconfig eth1 , I get inet addr: 192.168.56.11 and many more values.
How do I use Putty (ssh) here? I entered 192.168.56.11 on the Host Name and 80 on the Port Number, but Putty can’t connect.
I am trying to follow the guidelines from this course:
What exactly does Putty do? I don’t understand why I need to do this.
4 Answers 4
PuTTY will open a «network» between both machines. You’ll get a console (like the shell) when you’ll be connected. Really useful to administrate remote server from your computer.
Usually, the port is not 80, but 22.
For oracle vm virtual box:
1)Power of your machine
2)goto Settings -> Network -> Adapter1 -> Enable Network Adapter -> select «Bridge Adapter» in Attache To tab and click ‘ok» button
3) open terminal in virtual box and type» ifconfig»
in first paragraph
eth0 Link encap:Ethernet HWaddr 08:00:27:fb:d1:28 inet addr:172.16.2.199
4) Here ip address is «172.16.2.199» using this ip and port 22 ,you can login through putty and winscp also
![]()
Try opening terminal through VMWare’s console on Ubuntu and then run below given code:
sudo apt-get install openssh-server
I had faced the same issue.
Note: I assume you have already started the VM, importing the ISO image, and tried to access the machine with 10.X.X.X or 172.X.X.X range IP address from the Putty agent and got an time-out message.
Before making any changes to the network configuration on the VM or trying bridge-adapters, as suggested by many of the articles online, I suggest you to check 2 robust points which forms the bus for your VM on VirtualBox and Putty agent installed on your system.
2nd Point: Adding a host-only adapter, under the network settings of your VM.
If you follow these steps before booting up the VM for the first time, your VM will be allocated with a 192 range IP address (by the dhcp) the moment it boots up and starts running. Now all you need to do is, install and openssh-server and use the 192-range IP address with the Putty agent and Voila!!
Как подключиться к виртуальной машине VirtualBox по SSH
После установки серверного дистрибутива Linux на виртуальную машину VirtualBox вы можете обнаружить, что подключение по SSH не работает. Это связано с тем, что по умолчанию на VirtualBox используется подключение к интернету с помощью NAT.
При таком способе подключения у вас нет возможности подключаться к виртуальной машине из своей реальной операционной системы. В частности, вы не сможете подключиться по SSH.
В данной статье мы рассмотрим сразу два способа, как можно решить эту проблему. Первый вариант – проброс портов через NAT, а второй – использование сетевого моста. Оба этих способа сохраняют доступ к интернету на виртуальной машине.
Проброс портов для SSH
Для проброса портов вам нужно знать IP адрес, который присваивается виртуальной машине. Для этого запустите виртуальную машину и выполните на ней команду « ip addr » или « ifconfig ». В ответ вы получите информацию о сетевых подключениях, в которой будет указан и IP адрес. В нашем случае был получен IP адрес – « 10.0.2.15 ».
Обратите внимание, если в вашей системе нет команды « ifconfig », то ее нужно будет установить отдельно. В случае Debian и Ubuntu Linux это можно сделать с помощью команды « apt-get install net-tools ».

После того как мы узнали IP адрес виртуальную машину нужно выключить и открыть ее настройки в программе VirtualBox.

В настройках виртуальной машины нужно открыть раздел « Сеть », открыть дополнительные настройки и перейти к пробросу портов.

После этого откроется окно для проброса портов. Здесь нужно нажать на кнопку « Добавить » и заполнить следующие данные:
- Имя : SSH.
- Протокол : TCP.
- Адрес хоста : оставляем пустым или указываем 127.0.0.1.
- Порт хоста : любой свободный порт на вашей основной системе, например, 2222.
- Адрес гостя : IP адрес, который был присвоен вашей виртуальной машине. В нашем случае это 10.0.2.15.
- Порт гостя : порт SSH на виртуальной машине, по умолчанию – 22.
После проброса порта закрываем все окна с помощью кнопки « ОК ».

После этого можно подключаться к виртуальной машине по SSH. Для этого можно использовать клиент OpenSSH, который доступен в Windows 10. Поскольку порт « 2222 » на основной системе был проброшен на порт « 22 » на виртуальной машине, то для подключения по SSH нам нужно выполнить следующую команду:
Где « user » — это имя пользователя, а « 2222 » — используемый порт на основной системе.

Аналогичным способом выполняется подключение с помощью PuTTY . В поле « Host Name » указываем « localhost », а в поле « Port » — « 2222 ». Более подробно об OpenSSH и PyTTY в отдельной статье о подключении по SSH.

Как видно по скриншоту вверху, данный способ отлично работает, и мы успешно подключились по SSH к виртуальной машине VirtualBox.
Подключение через сетевой мост
Также есть альтернативный способ подключения к виртуальной машине по SSH для этого нужно изменить тип подключения с « NAT » на « Сетевой мост ». В этом случае виртуальная машина будет подключена к вашей локальной сети и получит IP адрес от вашего роутера из того же диапазона, что и ваша основная система.
Для этого нужно выключить виртуальную машину и зайти в ее свойства в программе VirtualBox. В настройках нужно зайти в раздел « Сеть » и включить тип подключения « Сетевой мост ».

После этого нужно запустить виртуальную машину и выполнить на ней команду « ip addr » или « ifconfig » для того, чтобы узнать, какой IP адрес она получила от роутера. В нашем случае был получен IP адрес « 192.168.1.214 ».

После этого к виртуальной машине можно подключаться по SSH. Для этого нужно просто использовать IP адрес, который был ей присвоен роутером. Например, для того чтобы подключиться с помощью клиента OpenSSH нужно выполнить следующую команду:
Где « user » — это имя пользователя, а « 192.168.1.214 » — это ее IP адрес.

Аналогично работает и подключение с помощью PuTTY. Вводим « 192.168.1.214 » и подключаемся по стандартному порту « 22 ».

Как и предыдущий способ, вариант с использованием сетевого моста отлично работает, при этом виртуальная машина не теряет доступа к интернету.
- Как сделать общую папку в VirtualBox
- Как подключиться по SSH из Windows 10
- Как запустить виртуальную машину VirtualBox из командной строки
- Как установить Linux на виртуальную машину
- Как установить Windows 7 или 10 на виртуальную машину
Создатель сайта comp-security.net, автор более 2000 статей о ремонте компьютеров, работе с программами, настройке операционных систем.
Задайте вопрос в комментариях под статьей или на странице «Задать вопрос» и вы обязательно получите ответ.
SSH to Local Linux VM With PuTTY
If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.
1. Introduction
Virtual Machines (VMs) are a flexible and cost-effective solution to replace physical servers. Running VMs on our host enables us to run environments for testing and development with multiple operating systems.
In this tutorial, we are going to check how to access our local VM via SSH, a network communication protocol. For that reason, we’ll focus on how virtual networking works and how the VM communicates with the physical interfaces of our computers.
2. Environment
After we create a local Linux VM, we obtain access through the console. However, when we enable SSH, we can manage our VM from our host using the command line.
For that reason, it’s essential to understand virtual networking. To demonstrate, we use two local RHEL-based guest machines running within Oracle VirtualBox. Then, we focus on setting up virtual networking and virtual interfaces for one of the guest machines.
In the next section, let’s discuss the virtual networking modes.
3. Virtual Networking
In general, we have three basic virtual networking modes.
3.1. Bridged
In the bridged networking mode, the virtual interface on the guest machine connects directly to the host’s physical interface. Moreover, the VM appears as another physical host on the external network. That is to say, it has an IP address that belongs to the physical network segment. As a result, the VM can access any service on the outside network as well as the host.
3.2. NAT
Unlike the bridged networking mode, the guest VM doesn’t have its IP address visible on the external network.
For example, Internet routers often use Network Address Translation (NAT) to prevent the outside from directly initiating a connection to its internal network.
Similarly, VMs within a private network can directly interact with each other. However, the VMs initiate communication with the external network through a NAT device. This virtualized adapter acts as a gateway to the outside:

In particular, the NAT device replaces the VM IP with the physical host address before forwarding the outgoing packets from the VM. On the other hand, incoming data requires the reverse translation – from physical address to internal VM address.
3.3. Host-Only
With this mode, we configure an isolated VM on the host. In other words, only VMs within the same internal network can communicate only with each other and with the host machine. Communication between the VM and the external network is not allowed.
4. Isolating Our VM
To run our virtual environment independently from the physical network where our host resides, we need to assign our VM a local IP. This allows us to restrict access to our VM from our host only.
On the other hand, we also need to ensure that our VM communicates with the services running on the outside network. Therefore, we limit our choice to NAT and host-only networking.
Next, we dive into the NAT configuration with VirtualBox.
5. Configuring NAT in VirtualBox
When we create a VM, VirtualBox assigns it the NAT option by default. This selection creates a separate NAT network composed of the host and the corresponding VM. So instead, we will use the NAT networking mode.
In contrast, the NAT networking mode preserves the internal communication between multiple VMs.
5.1. NAT Network Configuration
Firstly, let’s create a NAT network using the command VboxManage natnetwork:
With the –netname flag, we specify our NAT network name. Next, we use –network to define the corresponding network address and mask.
By default, the NAT adapter supports DHCP. However, since we will assign a static IP to our VM, let’s modify the previously created NatNetwork to remove the attached DHCP server :
Then, let’s list the NAT network configuration:
From the above, we see that we have successfully disabled the DHCP of NatNetwork.
5.2. Enable Port Forwarding
We previously saw that our VM sits behind a NAT device. In this case, the services running on our VM like SSH aren’t exposed to the outside world. Also, our host can’t access the VM. Therefore we need to set up port forwarding to allow SSH login to our VM from the host. Let’s enable SSH access to the VM from our host, continuing from the last step above:
Here, we name our port forwarding rule ssh_linuxvm1, keeping Protocol to its default tcp value. Also, to make sure that remote access isn’t possible from outside our host, we configure VirtualBox to listen on the localhost address 127.0.0.1 only.
Additionally, we define port 2222 on the host to point to port 22 on 10.0.2.5, linuxvm1.
Similarly, we can add a port forwarding rule for our second VM. However, we need to define a different port on the host and add the corresponding Linux guest IP.
5.3. Assigning NAT Network to VMs
Lastly, let’s assign NatNetwork to our guest machine linuxvm1 with the command VboxManage modifyvm:
With the –nic1 option, we attach NatNetwork to the first virtual adapter on the VM.
To verify, let’s display the linuxvm1 configuration with the command VboxManage showvminfo:
Next, let’s check how to configure the virtual network interface on our VM.
5.4. Configuring the Virtual Interface of the VM
We launch linuxvm1 and then log in from the console. In this case, we use nmcli, a NetworkManager tool, to configure the virtual interface. Firstly, let’s list the available devices using the command nmcli device:
We see that interface enp0s3 isn’t connected.
Next, we modify the connection enp0s3 to define the static IP address 10.0.2.5 and the gateway IP 10.0.2.1:
With the gw4 property, we add the NAT network gateway IP address, which enables our VM to route its outgoing traffic.
Also, let’s switch the interface IP assignment to manual (default is DHCP) and enable the connection activation on boot:
After that, we manually activate our connection:
Finally, to validate that enp0s3 is up, let’s run the ip command with the options address show and specify our interface name as an argument:
The configuration looks correct. Finally, let’s check access to linuxvm1 via ssh.
5.5. SSH Access
By default, the sshd service is running on our VM. We can verify with systemctl:
Further, from the VM, we confirm that port 22 is not blocked with the firewall-cmd command:
From the above output, we see that the SSH protocol is allowed.
Lastly, let’s access linuxvm1 via PuTTY. Instead of specifying our VM IP address and SSH port 22, we use 127.0.0.1 (localhost) and the destination port 2222 we set up earlier:

Once we accept the key, we can log in to linuxvm1.
6. Host-Only Networking With VirtualBox
Next, let’s add a host-only adapter to our VM. This allows us to SSH directly into our VM using its IP without configuring any port forwarding.
With host-only networking, VirtualBox creates a device that appears as a physical interface from the host. However, similar to a loopback interface, the host-only adapter is virtual, which means it doesn’t connect to a physical network. But it allows the VMs and host to talk to each other.
6.1. Host-Only Network Configuration
First, we check the available host-only adapter configuration:
Next, let’s disable the DHCP server of the host-only interface:
Now, we assign the host-only network to a second linuxvm1 virtual interface after turning off the VM:
After that, we can configure the corresponding virtual interface on linuxvm1.
6.2. Configuring the Second Virtual Interface of the VM
From linuxvm1, let’s check the new device name by running the nmcli device command:
Next, as a superuser, we configure a static ethernet connection for device enp0s8:
With the above, we set a static IP address 192.168.56.5 for our interface. Also, we use con-name to create a connection name that is relevant to the device name enp0s8 while we refer to the device name with ifname.
6.3. Direct SSH Login
Let’s login using PuTTY. Here, we enter the VM address 192.168.56.5 in the IP address field and the SSH port 22 in the Port field:

Now that we have two interfaces, we can use the host-only interface for SSH access from both the host and the other VM while we leave the NAT Network interface for external communication.
7. Conclusion
In this article, we talked about SSH access to a local VM. Using VirtualBox, we explored different virtual networking modes, highlighting their pros and cons.
After that, we saw that SSH access to a local VM requires enabling port forwarding on our host with a NAT Network. However, with the host-only mode, we can directly access our VM via SSH without extra configuration.
If you have a few years of experience in the Linux ecosystem, and you’re interested in sharing that experience with the community, have a look at our Contribution Guidelines.