Score:0

How to ssh onto a VirtualBox VM from a different computer within the same network?

cn flag

I have two VMs on two different computers at home. On one of them (let's call it comp1; comp1 has a Windows 10 host with an Ubuntu virtual machine), I already set up the virtual machine's network such that I can ssh onto it from the host. I set it up by doing the following the instruction from this site (https://medium.com/nycdev/how-to-ssh-from-a-host-to-a-guest-vm-on-your-local-machine-6cb4c91acc2e).

When I try to ssh onto comp1's Ubuntu virtual machine, I get the following message:

ssh: connect to host 127.0.0.1 port 5679: Connection refused

Please let me know if there are more setup that I need to be done on comp2's VM in order for the two to connect.

Gloat avatar
hk flag
Try to user comp1's ip address to SSH to, `ssh comp1ip -p 5679`
Gloat avatar
hk flag
127.0.0.1 is a loopback address and is going to try and ssh to the local machine, for comp1 it works because it's just ssh to the local machine at port 5679 than virtual box can handle the NAT to send that ssh to the VM.
Score:4
in flag

The instructions you followed are technically accurate, but they’re also more complicated than is necessary in most non-corporate environments. You do not need to set up port forwarding or a virtual network device for this to work.

In VirtualBox, do this:

  1. Eliminate the port forwarding rules for the VM
  2. Disconnect the virtual network interface from the VM
  3. Set the network to “Bridged” mode, selecting your main network adapter as the bridge, then under “Advanced” make sure the promiscuous mode to “Allow All”

Now the following things are possible:

  1. the VM can receive an IP address from the DHCP host on the network (or you can configure a static IP within the VM itself)
  2. the VM can receive all traffic directed to it and choose what it responds to via ufw rules and the like

In the VM:

  1. Confirm OpenSSH is set with ufw:
    sudo ufw status
    
    If you see a message saying that ufw is disabled, then leave it be. If it’s enabled, you want to confirm you have a record that shows ALLOW next to port 22.
  2. Confirm the IP address of the VM:
    ip a
    
    You will see information about all of your network interfaces. You want the IP address that matches your network pattern, such as 192.168.0.x.
  3. On a different computer, SSH into the VM:
    ssh [email protected]
    
    Be sure to replace the username with the proper name, and the IP address with the proper address.

If everything is good, follow the same steps for the other VM.

Kane Billiot avatar
cn flag
Thank you for your help. Can you explain the setting up VirtualBox part a little bit more? I tried to follow what you laid out, but now I get the error "Connection failed: Activation of network connection failed" when I start the VM
Kane Billiot avatar
cn flag
Specifically, I did the following: 1) File>Host Network Manager>Delete Host-only network, 2) In the VM's setting, System>Uncheck Network under Boot Order, 3) Network>Uncheck Enable Network Adapter on 2,3, and 4, 4) (under Adapter 1) delete Port forwarding rule, select "Attached to: Bridged Adapter", "Name: Intel(R) Dual Band Wireless-AC 3168", Advanced> Adapter Type: Intel PRO/1000 MT Desktop (82540EM), Promiscuous Mode: Allow All, Cable Connected>Uncheck
in flag
You *unchecked* “cable connected”? That means there can be no network connection, only the device
Kane Billiot avatar
cn flag
I checked the box again, but the problem persists.
mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.