Question: I've got a Ubuntu 16.04 box on an Intel NUC for HTPC purposes (running Kodi). Most of the time it's outputting audio to the TV via HDMI (one day will be via a receiver) however occasionally I'd like to output audio to my Bluetooth headphones to avoid bothering others. The box does not have a GUI installed on it and I'd like to keep it that way.

I don't want to install Pulseaudio if at all possible - ALSA is much simpler and seems to be better suited to Kodi.

What I want to achieve:

* The HTPC should automatically connect to the Bluetooth headphones when I turn them on (having manually paired them once). I don't mind if there's a script running in the background periodically trying to do that.
* The Bluetooth headphones should be available as a separate ALSA output device in Kodi
* I don't mind manually switching the output device in Kodi from HDMI to the headphones

What I've tried so far:

* I'm able to "see" my Bluetooth headphones using hcitool scan
* I'm able to see them using bluetoothctl and pair with them, however "connecting" fails (I believe due to missing Pulseaudio)
* I've tried defining an ALSA audio device for them (approximately following the guide here: [Bluetooth/Alsa - Debian Wiki](https://wiki.debian.org/Bluetooth/Alsa)) however when I try and "aplay" to that device it complains about a missing .so module (libasound\_module\_pcm\_bluetooth.so)

Hopefully someone has done this before (on a recent version of Ubuntu)

**Update**
I've found the reason it's looking for "libasound\_module\_pcm\_bluetooth.so" is based on the "type" in the asound.conf declaration. So I guess I need to use one of the modules that is present on my machine (under /usr/lib/x86\_64-linux-gnu/alsa-lib/).

Answer: 
In order to fix this, you can either reinstall `sudo`, or download a default `/etc/sudoers` and edit it. Both ways require these steps: First, restart your computer. When the Grub screen displays, instead of choosing `Ubuntu xxx`, choose `Advanced options for Ubuntu xxx`. Under `Advanced Options`, choose `Recovery mode`. The second step is to mount your partitions `rw`. To do this, choose `Clean packages`, `Ok`, and then when you see the recovery screen again, select `Root shell`. Enable the wifi from the root shell. Either reinstall `sudo`:

```
apt-get install --reinstall sudo

```

or insert this into `/etc/sudoers`:

```
# /etc/sudoers
#
# This file MUST be edited with the 'visudo' command as root.
#
# See the man page for details on how to write a sudoers file.
#

Defaults    env_reset

# Uncomment to allow members of group sudo to not need a password
%sudo ALL=NOPASSWD: ALL

# Host alias specification

# User alias specification

# Cmnd alias specification

# User privilege specification
root    ALL=(ALL) ALL

# Members of the admin group may gain root privileges
# %admin ALL=(ALL) ALL

```

(from [Sudoers Ubuntu Wiki](https://help.ubuntu.com/community/Sudoers))

Before restarting, `su` back to your normal user, and try `sudo apt-get upgrade` or anything with `sudo`. If it works, then reboot. Otherwise, comment with the error message.
You obviously can access the internet on another machine because you posted this question. You can create an Ubuntu live CD, boot into it, and fix `sudo` with the following steps. Mount the partitions of your installation to recreate the filesystem at `/mnt` (`sudo mount /dev/<whatever> /mnt`, `mkdir -p /mnt/home && sudo mount /dev/<whatever2> /mnt/home`...). Insert the default sudoers file from the [Ubuntu wiki](https://help.ubuntu.com/community/Sudoers) into `/mnt/etc/sudoers`. Reboot into your system and `sudo` should work.