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

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.


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.