How to ssh into a server running on a home network, behind a router?
There are multiple things you need to do:
1) Like fkraiem mentioned in his comment, make sure your VM is accessible on the local network. Using a 'bridge' network connection in the VM settings should accomplish that. Then using one of your other computers (even your host), check to see if you can log into the SSH server. If you can, congrats, let's move to the next step.
2) Next you need to know how to port forward on your router. Since you didn't mention what router you have, you will have to figure that out yourself. Port 22 is the one used by SSH. Of course you can listen on a higher port on the router to avoid having your logs filled up by a bunch of script kiddies trying to hack into your server, and then forward the port to 22 on your server. For example, lets imagine your local IP for your server is 192.168.0.10. Your WAN (Internet) IP is 99.99.99.99.
99.99.99.99:60022 -> Router -> 192.168.0.10:22
What you want to do is tell your router to listen on port 60022, and forward that to IP 192.168.0.10, and port 22.
To figure out what your WAN IP is, simply google 'what is my IP address'. There are other ways, but it is the easiest.
Now, after you setup the router, try to connect with an outside computer to your WAN IP with the higher port. You could tether with your cellphone to a laptop to accomplish that.
If you could connect with that, congrats again.
3) Now you have to make sure your IP addresses stay static on your local network, and you would need to get a dynamic DNS entry for your WAN IP address. This way you would use a domain name instead of your WAN IP. Google 'dynamic dns' to find some free service.
Hope that helped.
My personal setup is the following:
-
On the router forward port 22 from remote machine to 2222 of the local machine, let's say 192.168.0.33 for example. That way you can still have ssh access to the main OS on the machine, while 2222 is for the virtual OS.
- On the virtual box, forward host OS 192.168.0.33 port 2222 to the guest OS's port 22. The IP of the guest can be found with the
ifconfig
command on the guest itself.
- On the virtual box, forward host OS 192.168.0.33 port 2222 to the guest OS's port 22. The IP of the guest can be found with the
Now if you know your router's IP, you can ssh to your router's IP, and it will be automatically forwarded to port 2222 of your physical machine. Physical machine will give that connection to port 22 of virtual machine (provided that VM is running).
If you want to ssh from local network, use ssh -p 222 192.168.0.33