How to Easily Fix Bluetooth Device Auto-Connect Issues in Linux

If you've been using Linux for a while, you probably know that Bluetooth and Linux don't always work seamlessly together. Connecting Bluetooth devices to your Linux system can be a hassle, and it's frustrating when your devices don't auto-connect. I recently upgraded to Ubuntu 20.04 and experienced this issue firsthand. After a lot of digging, I found some solutions to fix the “Bluetooth device doesn't auto-connect in Ubuntu” problem.

AutoEnable

The first step is to ensure that your Bluetooth module is working and turned on. Check if AutoEnable is enabled in the Bluetooth configuration file. You can do this by opening the terminal and typing:

sudo nano /etc/bluetooth/main.conf

If you see the line “AutoEnable=true” at the bottom of the file, you're all set. If not, add the line “AutoEnable=true” and save the file. This step may not be necessary for Bluetooth audio devices, but it can fix auto-connect issues with devices like mice, webcams, or keyboards.

auto-enable-bluetooth.conf

Trust Device

If the previous step didn't solve the problem, the issue might be that Ubuntu doesn't trust your Bluetooth device. This can cause authentication failures when the device tries to auto-connect. To fix this, you need to add your device to the trusted list.

First, find the MAC address of your Bluetooth device. Go to the top bar, click on the battery icon, then click on “Bluetooth Settings.” Look for your device name and click on it to get the MAC address.

bluetooth-settings-bluetooth

Once you have the MAC address, open the terminal and type the following command:

bluetoothctl trust mac_address

To verify that the device is added to the trusted list, use the command:

sudo bluetoothctl info mac_address

Now try restarting your Bluetooth service, and the device should auto-connect.

Re-pair Bluetooth Device

If the previous steps didn't work, you can try removing the Bluetooth device and pairing it again. Sometimes, Ubuntu can mistake the device type or class, which can cause auto-connect issues. To remove the device, use the command:

bluetoothctl remove mac_address

Put your headphones into pairing mode and run the following command:

bluetoothctl connect mac_address

Restart your Bluetooth service and check if the device auto-connects now.

Reinstall Bluetooth

If nothing else works, reinstalling the Bluetooth package might fix the issue. BlueZ is the official Linux Bluetooth stack, and reinstalling it can resolve driver issues. To reinstall BlueZ, use the command:

sudo apt reinstall bluez

After reinstalling, enable and start the Bluetooth service:

sudo systemctl enable bluetooth.service
sudo systemctl start bluetooth.service

This might help fix the automatic reconnect of your Bluetooth device.

Using a Python Script

If none of the previous steps worked, you can try using a Python script called “bluetooth-autoconnect.” This script automatically connects to all paired and trusted Bluetooth devices. However, it's not available to install directly, so you'll need to download and configure it manually.

First, download the zip file from GitHub or clone the repository to your home directory using this command:

git clone https://github.com/jrouleau/bluetooth-autoconnect.git

Move the service and scripts to their respective locations:

sudo cp bluetooth-autoconnect/bluetooth-autoconnect.service /etc/systemd/system/
sudo cp '/home/pratik/bluetooth-autoconnect/bluetooth-autoconnect' /usr/bin/

Enable and start the service:

sudo systemctl enable bluetooth-autoconnect.service
sudo systemctl start bluetooth-autoconnect.service

Now the service will try to reconnect to every paired and trusted Bluetooth device. Keep in mind that you won't be able to pair your Bluetooth device with other systems unless you turn off your Linux machine's Bluetooth.

Conclusion

Bluetooth connectivity issues can be frustrating, but with these steps, you should be able to fix the auto-connect problem in Linux. Remember that not all solutions work for every device, so try them out and see which one works best for you. If you have any other tips or solutions, feel free to share them in the comments.