Search code examples
linuxsshvirtualization

SSH into Linux Guest Virtual machine from External Source?


I currently have a Linux server running as a guest on Virtualbox using Windows 8.1 as the host. I can SSH from my Windows host into the guest with no problem. But how do I set it up so I can SSH from an external machine that is not within the local network, like from another country, for example? All the examples I see online are SSHing from the host to the guest only.

My Linux guest is using a bridged network and using dynamic IP.

Thank you very much!


Solution

  • Ok, so I got it figured out!

    I set up 2 networks in Virtualbox: NAT (eth0) and bridged (eth1). NAT allows for internet access from the Linux guest, and bridged allows the Windows host to send the data through to the Linux guest. Both are given dynamic IP in the Linux guest.

    In the port forwarding section for NAT of Virtualbox, I have the interal IP address of the Windows host and the IP address of the bridged connection as guest. In my case, it's 192.168.1.1 and 192.168.1.8, respectively. Ports are 2222 and 22, respectively.

    For my router, I enabled port forwarding to port 2222 of the Windows host (192.168.1.1).

    In Windows Firewall, I opened up port 2222 for connections.

    And that's it! I can now SSH to the Linux guest from computers in the local network via (username)@192.168.1.8, and via (username)@Windows_host_public_IP from a computer outside the local network.