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:
$ 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.
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"
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"
If you are still unable to ssh to your guest virtual machine check the following:
$ netstat -ant | grep 2222