Contents[Hide]

You have just installed and running some Linux distribution within the VirtualBox guest machine. At the same time, you have discovered that you are unable to create a ssh ( Secure Shell ) connection from your host operating system to your new VirtualBox guest machine. The default behavior of the VirtualBox does not allow that connection to happen.

There are two ( possibly more ) solutions to this problem. First solution is to create a bridged network interface and link your virtual guest by changing a guest's network interface settings. This may not be as easy as it sounds, but generally it works well and setup is easy. The second solution involves a port forwarding of a port 22 to your virtual guest machine. This solution is very easy to implement, but it does not work with older VirtualBox versions.

This article will guide you to implement the easier port forwarding solution. First check if your VirtualBox version supports a NAT port forwarding by executing a following command:

1. Check for VirtualBox NAT forward availability

$ VBoxManage modifyvm | grep natpf

If you do not observe any output you would need to upgrade your VirtualBox software. Next, open up a terminal on a host operating system.

2. create SSH port forward

Find a name of your virtual guest machine: NOTE: The following command needs to be run by a user who has an ownership of the above virtual machine as this command will display only virtual machines which a current user owns. In most cases this is NOT a root user.

$ VBoxManage list vms

Execution of a following command on the host operating system we redirect any traffic coming on port 2222 to a port 22 listening on a guest virtual machine with a name "Ubuntu_10.04".

$ VBoxManage modifyvm "Ubuntu_10.04" --natpf1 "host2guest-ssh,tcp,,2222,,22"

3. Login to guest SSH using port forward

All done. Now start your guest virtual machine and ssh to with a following command:

$ ssh -p 2222 username@localhost

If your guest operating system is using a static IP address you can modify the above port forward command to specify a guest IP address.:

$ VBoxManage modifyvm "Ubuntu_10.04" --natpf1 "host2guest-ssh,tcp,,2222,10.0.2.220,22"

4. Troubleshooting,

If you are still unable to ssh to your guest virtual machine check the following:

  • check whether your host operating system is listening on port 2222

$ netstat -ant | grep 2222

  • check if sshd is installed and running on your guest operating system.



Free Linux eBooks

Do you have the right skills?

Our IT Skills Watch page reflects an up to date IT skills demand leaning towards the Linux and Unix environment. We have considered a number of skills and operating systems.

See the result...

Linux Online Training

Learn to run Linux servers and prepare for LPI certification with Linux Academy. 104 available video lessons with PDF course notes with your own server!

Go to top