How to set up a ssh connection from Host to Guest VirtualBox

  1. VM’s Settings -> System -> check “Enable I/O APIC.”
  2. Shut the guest down, and use VirtualBox Settings to enable a second virtual network adapter, named (by default) vboxnet0.
  3. Inside Guest edit /etc/network/interfaces file or analogue and append the following lines:
    auto eth1
    iface eth1 inet dhcp
    
    

    or

    allow-hotplug eth1
    iface eth1 inet dhcp
  4. In Guest start the interface: ifup eth1
  5. Test ssh root@[ip address from ifconfig in Guest] from Host system.
  6. Make sure you have root login enabled in Guest /etc/sshd_config settings.

	    		
 

How to set up an ssh connection from your wi-fi network

All the manuals suggest using port forwarding, like:

$ ssh user@remote_host -R 5555:localhost:22

but this doesn’t work if ssh tunnel shuts down. There is actually an autossh to solve this problem:

$ sudo autossh -M 0 -4 -N root@remote_host -R remote_port:localhost:22 -o “ServerAliveInterval 60” -o “ServerAliveCountMax 3” -o BatchMode=yes -o StrictHostKeyChecking=no -i /home/user/.ssh/id_rsa

-i allows you to use pub key to authenticate yourself on the remote host, so you won’t have to always use a password