While the point of having a virtual machine is its separation and isolation from the host machine you also want to interact with the system. VirtualBox offers tools like shared clipboard and folders but many users are used to SSH for administration.
Here we show to ssh into a virtual machine running with VirtualBox. To be specific, we have installed Ubuntu 16.04
- Ubuntu 16.04 64 bit running on a virtual machine
- Virtual Box 5.2.6
- Host-Machine: Windows 10 + BitVise SSH Client 7.2
2. Set up ssh server on guest machine
The first step is to make sure, ssh server is running on our virtual system.
You can do this by checking if ssh daemon sshd listening on port 22
sudo netstat -tulpn | grep ssh
If ssh is not installed and running you can do this with apt-get:
sudo apt-get install openssh-server
3. Enable SSH port forwarding in host machine
We set up the host port as 2222 and the guest port as 22. In other words, when we save this setting VirtualBox will be listening on our host machine on port 2222 and will forward any incoming traffic to our guest machines ip and port 22.
4. Connect with host’s SSH client to virtual machine
So what is left is only to connect via a SSH client to our host machine’s ip address and port 2222. What about credentials? Since our ssh request will be forwarded we use the virtual machine’s ssh login credentials and authentication settings.
5. Conclusion / Troubleshooting
This process was pretty straight forward but there are things that might go wrong. So we have a dedicated troubleshooting article set up if things are no working quite well.