VirtualBox SSH Port 22 Forwarding

To set up SSH access to a VirtualBox VM, you need to forward the appropriate ports.

Open Virtual Box preferences, select the Network tab, select Adapter 1, and click on the "Port Forwarding" button. Add a new rule. Host IP and Guest IP are optional and should be blank. Set Host Port to 2222 and Guest Port to 22.

Note: These Port Forwarding settings take effect immediately in VirtualBox 4, so no need to restart.

Note: Listening on ports 0-1023 requires root permissions, so use a Host Port 1024 and higher. In this case we are using 2222 ("22" + "22").

Connect to the virtual machine via SSH with:

ssh -l myusername -p 2222 localhost

Additionally, to transfer files to the virtual machine guest, use the following scp command:

scp -P 2222 /path/to/source/file.txt myusername@localhost:/path/to/destination/
View this page on GitHub.
Posted .

4 comments

  1. anonymous

    Make sure the client also has ssh server installed and running:

    sudo apt-get install openssh-server

  2. anonymous

    This is a correct solution to ssh from host to virtual box Linux! Thanks man!

  3. anonymous

    I found this very useful and got it working. Thanks.

  4. anonymous

    It is working and useful.

Leave a Reply