If you have been using Linux for a while, you would know Bluetooth and Linux don’t go hand in hand. Whatever may be the reason, it’s always a hassle to connect Bluetooth devices to your Linux system. Recently, since my upgrade to Ubuntu 20.04, I have come to notice that Bluetooth devices don’t just auto-connect back to my system. I dug on it a lot and here are ways to fix “Bluetooth device doesn’t auto-connect in Ubuntu”.
Fix “Bluetooth device doesn’t auto-connect” in Ubuntu
There is no one-stop solution to this problem and your issue might differ from mine. For instance, my Bluetooth headphones auto-connect back to my Ubuntu system as soon as I power it on. But, the next second, it disconnects again and I have to connect it every time manually.
So, whatever may be the Bluetooth device, here’s a step-by-step fix and do comment and let me know which of them works for you.
Step 1. AutoEnable
Foremost, you need to ensure that you have a working Bluetooth module and it’s turned on. Once, we have that out of the way, we need to check if AutoEnable is turned on. Auto enable ensures that the Bluetooth module is turned on after every restart. Additionally, if you plug in a Bluetooth USB device or module, AutoEnable ensures that it can start without a reboot.
To ensure AutoEnable is turned on, we need to dig in the Bluetooth configuration file. To do that, use the following command.
sudo nano /etc/bluetooth/main.conf
In the Bluetooth configuration file, navigate to the bottom. In case you see a line stating “AutoEnable=true”, it’s all good. In case you don’t, AutoEnable is turned off. Hence, we’ll have to add the following line at the end of the file.
This step is not that important for a Bluetooth audio device but can fix a Bluetooth mouse, webcam, or keyboard auto-connect issue.
Step 2. Trust Device
If the above method didn’t solve the problem, a reason might be that the Bluetooth device isn’t trusted by Ubuntu. This causes an authentication failure when the device tries to auto-connect. To make sure your Bluetooth device is trusted, we need to add it to the trusted list.
To do that, we would foremost need the Bluetooth device MAC address. To get the MAC address, you need to connect your Bluetooth device with your system or at least make it discoverable. Next, head over to the top bar and click on the battery icon. From the extended drop-down, click on the Bluetooth icon and then Bluetooth Settings.
Under Bluetooth settings, look for your Bluetooth device name and click on it. From the pop-up menu, you will get the device MAC Address.
Once we have the device MAC address, hit the “Alt+Ctrl+T” to open the terminal. On the terminal, type the following command and hit Enter.
bluetoothctl trust mac_address
To verify the device is added to the trusted list, hit the following command.
sudo bluetoothctl info mac_address
Now, try and restart your Bluetooth service, the device should auto-connect now.
Step 3. Re-pair Bluetooth device
In case things don’t work out, you can try removing the Bluetooth device and pairing it back again. At times, Ubuntu can mistake the Bluetooth device type or class. For instance, it can take the headphone device class as a Bluetooth keyboard. This issue can be fixed by a re-pairing. You can do that through the GUI by removing the device but if you are a keyboard ninja like me, below is the command.
bluetoothctl remove mac_address
Put your headphones into pairing mode and run the following command
bluetoothctl connect mac_address
Once done, restart your Bluetooth and see if the device auto-connects.
Step 4. Reinstall Bluetooth
This is the last resort if things don’t work out. A reinstall might fix the Bluetooth and other driver issues. BlueZ is the official Linux Bluetooth stack. To reinstall Bluetooth, we need to reinstall the BlueZ package. To do that, use the following command.
sudo apt reinstall bluez
Once you have reinstalled Bluez, enable and start the Bluetooth service by using the following command.
sudo systemctl enable bluetooth.service sudo systemctl start bluetooth.service
Now, this might help you to fix the automatic reconnect of the Bluetooth device. In case, it doesn’t lets move to the next step.
Step 5. Script
In case the above steps didn’t work you, we are in the same shoes. While I was about to give up on this article altogether, I stumbled upon a Python script on GitHub called bluetooth-autoconnect. It’s a python script that automatically connects to all paired and trusted Bluetooth devices. However, the script is not available to install directly on Flatpak or Apt repository. Hence, we need to manually download and configure the service.
First of all, download the zip file from GitHub or use the following command to clone the repository to your home directory.
git clone https://github.com/jrouleau/bluetooth-autoconnect.git
Now that we have the repository downloaded we need to move the service and scripts to their respective location before we start the service. In my case, I am using systemd architecture, hence the file destinations mentioned would be applicable to distros like ArchLinux, Ubuntu, Debian, etc. In case you use non-systemd distros, kindly google your service directories.
sudo cp bluetooth-autoconnect/bluetooth-autoconnect.service /etc/systemd/system/ sudo cp '/home/pratik/bluetooth-autoconnect/bluetooth-autoconnect' /usr/bin/
Once, we have successfully copied the service to the respective directories, let’s enable and start the service. To do that, use the following command.
sudo systemctl enable bluetooth-autoconnect.service sudo systemctl start bluetooth-autoconnect.service
Now, that we have the service started, it’ll try to reconnect to every paired and trusted Bluetooth device. The only caveat with this method is that you won’t be able to pair your Bluetooth device with other systems without switching off your Linux machine’s Bluetooth. Since the device would always try to connect with your Bluetooth device.
This article took me through dozens of forums and articles on the web. I tried udev scripts to PulseAudio to Bluez Manager but none of them could do the autoconnect job. Hence, I omitted them from this article. In my journey with Linux systems, apart from the lack of good professional apps, Bluetooth has been the second-most problem. I could never arrive at the conclusion that whether it’s the manufacturer driver issue or something Linux hasn’t figured it out yet.
Let me know your experience down in the comments and we could work out a solution together.