Some of these steps are easily forgotten, leading to no shared folders automatically mounting. The process to debug this can be a hassle, and there are far too many workaround mount methods on the net, including manual fstab entries etc, none of which should be necessary.

Generally one of the following prerequisites is missing:

  • Linux Headers
  • Build tools
  • Guest kernel modules
  • Group permissions

Also, ensure that Virtualbox is uptodate. Old versions of virtualbox often don’t play nicely with newer operating systems.

Here is list of commands, run as root to successfully install on Ubuntu 18.04:

UPDATE November 2019: This approach is NOT recommended, see below.

apt-get install build-essential linux-headers-$(uname -r)\
virtualbox-guest-dkms dkms virtualbox-guest-additions-iso
usermod -a -G vboxsf <USERNAME> 
reboot 

To install guest additions, mount the iso, run the installer and reboot:

mount /usr/share/virtualbox/VBoxGuestAdditions.iso /mnt
cd /mnt
./VBoxLinuxAdditions.run
reboot

If all else fails, check the log at /var/log/vboxadd-install.log

Update November 2019:

The ISO in the apt repos may not match the host version of virtualbox, resulting in shared folders not working. If at all possible, insert the guest additions ISO from the host. For my headless system, the easiest way is to ssh on using X (from Mac OS I use ssh -Y), show the VM in question then use insert guest additions ISO from the devices menu. The commands to execute are then:

sudo mount /dev/cdrom /mnt
sudo ./mnt/VBoxLinuxAdditions.run
reboot