Suppose you want to install Linux on your Macbook with VirtualBox. Since GUI is so heavy and resources-consuming, you may want to run Linux guest system in the headless mode and ssh into the guest system from your Macbook. The following shall let you do so.
1. Select Guest system in VirtualBox menu open up settings.
2. In the Network tab, make sure you have enabled an adapter with NAT.
3. Open up Advanced menu and click Port Forwarding.
4. Create a rule where Protocol = TCP, Host IP = 127.0.0.1, Host Port = 2222, Guest IP = 10.0.2.15, and Guest Port = 22.
5. Now, install openssh-server on your guest system, and you should be good to go by running the command from your host:
$ ssh -p 2222 email@example.com