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:
- Eliminate the port forwarding rules for the VM
- Disconnect the virtual network interface from the VM
- 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:
- 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)
- the VM can receive all traffic directed to it and choose what it responds to via
ufw
rules and the like
In the VM:
- Confirm OpenSSH is set with
ufw
:
If you see a message saying thatsudo ufw status
ufw
is disabled, then leave it be. If it’s enabled, you want to confirm you have a record that showsALLOW
next to port 22. - Confirm the IP address of the VM:
You will see information about all of your network interfaces. You want the IP address that matches your network pattern, such asip a
192.168.0.x
. - On a different computer, SSH into the VM:
Be sure to replace the username with the proper name, and the IP address with the proper address.ssh [email protected]
If everything is good, follow the same steps for the other VM.