Is it possible to “SSH” into my virtual machine remotely?

My home computer: Windows 7 laptop also running an Ubuntu virtual machine via VirtualBox with a bridged network connection (as opposed to NAT).

My work computer: A Windows 7 computer.

I want to SSH into my home machine remotely from my work computer because I want to be able to run / manipulate my LAMP webserver (which involves MySQL stuff, yes). I am running Apache on the VirtualBox and it would be great to have control from afar.

To my understanding, SSH is a way to "log in" to your terminal remotely, yes? I've Googled this subject (which led me to things like PuTTY) but am having difficulty understanding how all of this works or what I need to set up or keep in mind as a beginner.

However it would also be nice to have the ability to SSH in from anywhere, if possible! that'd be really convenient.


To install/configure SSH you should check out one of many guides you can find browsing the internet, this one for example.

You can connect to your viritual machiene via SSH using the following command:

ssh user@ip

You will thereafter be prompted to enter your password. To be able to connect you need, as said, an IP. When connecting locally you have a local IP. You can check this address for the current system using the ifconfig command. Example:

ifconfig
eth0      Link encap:Ethernet  HWaddr e8:39:35:42:ed:96  
          inet addr:191.13.238.54  Bcast:191.13.255.255  Mask:255.255.0.0
          inet6 addr: fe80::ea39:35ff:fe42:ed96/64 Scope:Link
          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
          RX packets:85385 errors:0 dropped:0 overruns:0 frame:0
          TX packets:77885 errors:0 dropped:0 overruns:0 carrier:0
          collisions:0 txqueuelen:1000 
          RX bytes:48235010 (48.2 MB)  TX bytes:9640323 (9.6 MB)

The inet addr being your local IP address, in my case 191.13.238.54. If I would connect to my SSH server on my computer I would therefore execute the following:

ssh [email protected]

To allow connecting from outside of your network you are required to forward the incoming traffic, on the port SSH is running on, to your local IP address via a admin panel for your router. Some routers may not support this and the admin panel work differently between manufacturers. You can always call customer support if you are stuck with this issue.

To check your "global" IP address you can visit this website: what's my IP?

When connected to your "server" through SSH you can perform various tasks such as SQL:

mysql -u root -p -h 127.0.0.0

In the above scenario root is the user, password is enabled through -p and the host is 127.0.0.0/localhost (your local computer).

You can also access files using nano or any other text editor like the very popular and powerful (and complicated) vim. All in all you now have the power of a terminal in your hands, that is if you connect via PuTTY.

Connecting via, say Ubuntu's file manager, gives you a better visual experience and allow you to edit files in a GUI editor rather than through the command line. Similar programs exist on Windows, you'll have to figure that one out yourself.


If you want to ssh to your VM (or even your computer) from anywhere your host(work) computer must have an IP which you may rent from your ISP if they offer.

But if you want to ssh to your VM from your own computer it's due to your VirtualBox setup. Navigate to your VM settings, network tab. Attach your VM to NAT and in advanced, you should setup port forwarding as the following:

Protocol -> TCP, HostIP -> 127.0.0.1, Host Port -> 1222, GuestIP -> (your VM ip shown via command ifconfig), GuestPort -> 22

Finally you can ssh to your machine via ssh [email protected] -p 1222