How to install Virtual Box Guest Additions on Debian?

From my experience Guest Additions that are bundled with VirtualBox work better. Here are steps to install them. All commands have to be executed as root.

  1. Install kernel headers, build tools and DKMS:

     # apt update
     # apt install build-essential dkms
    

    DKMS isn't required, but it will keep Guest Additions working after kernel updates. Otherwise you'd have to reinstall them.

  2. Insert the virtual CD using appropriate menu item in VirtualBox menu:

    Please note that this is a host menu. It's not inside the Debian VM. In fullscreen you may have to move your mouse to the top of the screen to reveal it. If it's hidden in windowed mode, see this question.

    Menu screenshot

  3. Mount the CD:

     # mount /dev/cdrom /media/cdrom
    
  4. cd into the mounted directory:

     # cd /media/cdrom
    
  5. Run the installer:

     # ./VBoxLinuxAdditions.run
    

Or alternatively, if you really want to install from repository:

# apt install virtualbox-guest-utils

This works for me (Debian GNU/Linux 8 (Jessie) 64-bit):

  1. Login as root with terminal command su press Enter and then type your root password
  2. Update your APT database with apt-get update
  3. Install the latest security updates with apt-get upgrade
  4. Install required packages with apt-get install build-essential module-assistant
  5. Configure your system for building kernel modules by running m-a prepare
  6. Click on Install Guest Additions… from the VirtualBox Devices menu
  7. Run mount /dev/sr0 /media/cdrom
  8. Run sh /media/cdrom/VBoxLinuxAdditions.run, and follow the instructions on screen.

I got permissions denied when I tried to run "VBoxLinuxAdditions.run" so I changed the file /etc/fstab to user,exec. Other than that the steps that gronostaj mentioned worked perfectly.

Explanation from virtualbox forum:

..the filesystem is mounted with the noexec option, so the execute permission bits on all files are ignored, and you cannot directly execute any program residing on this filesystem. Note that the noexec mount option is implied by the user option in /etc/fstab. ... If you use user and want to have executable files, use user,exec.