How to fix “Bluetooth device doesn’t auto-connect†in Linux.
If you’ve been using Linux for a while, you would know that Bluetooth and Linux don’t go hand in hand. Whatever the reason, it’s always difficult to connect Bluetooth devices to your Linux system. Recently, after upgrading to Ubuntu 20.04, I noticed that Bluetooth devices don’t just automatically connect to my system. I have been digging into this a lot and here are the ways to fix “Bluetooth device does not connect automatically in Ubuntu”.
Fix “Bluetooth device does not connect automatically” in Ubuntu
There is no universal solution to this problem, and your problem may be different from mine. For example, my Bluetooth headphones automatically connect to my Ubuntu system as soon as I turn it on. But the next second it disconnects again and I have to reconnect it manually every time.
So, whatever the bluetooth device is, here is a step by step solution, leave a comment and let me know which one works for you.
Step 1. Enable automatic
First of all, you need to make sure that you have a working Bluetooth module and that it is turned on. Once this is done, we need to check if AutoEnable is enabled. Auto power-on ensures that the Bluetooth module is enabled after every restart. Also, if you plug in a USB device or Bluetooth module, AutoEnable ensures that it can start without rebooting.
To make sure AutoEnable is enabled we need to dig into the bluetooth config file. To do this, use the following command. sudo nano /etc/bluetooth/main.conf
In the bluetooth config file, go to the very bottom. If you see the line “AutoEnable = true”, everything is fine. If you don’t, AutoEnable is disabled. Hence, we will need to add the following line to the end of the file. AutoEnable = true
This step is not as critical for a Bluetooth audio device, but may fix the issue with automatic connection of a Bluetooth mouse, webcam, or keyboard.
Read: How to Fix AirPods Not Working in Ubuntu
Step 2. Trust the device
If the above method does not solve the problem, the reason may be that the Bluetooth device is not trusted by Ubuntu. This causes authentication to fail when the device tries to connect automatically. To make sure your Bluetooth device is trusted, we need to add it to the trusted list.
To do this, we first need the MAC address of the Bluetooth device. To get a MAC address, you need to connect a Bluetooth device to your system, or at least make it discoverable. Then go to the top panel and click on the battery icon. In the expanded drop-down list, click the Bluetooth icon and then Bluetooth Options.
In Bluetooth settings, find the name of your Bluetooth device and click it. In the pop-up menu, you will get the MAC address of the device.
After obtaining the MAC address of the device, press Alt + Ctrl + T to open a terminal. In the terminal, type the following command and press Enter. bluetoothctl trust mac_address
To make sure the device is added to the trusted list, press the following command. sudo bluetoothctl information mac_address
Now try restarting the Bluetooth service, the device should connect automatically.
Step 3. Re-pair the Bluetooth device
If something doesn’t work, try removing the Bluetooth device and reconnecting it. Sometimes Ubuntu may mistakenly indicate the type or class of the Bluetooth device. For example, it can adopt the headphone class as a Bluetooth keyboard. This issue can be resolved by re-pairing. You can do this through the GUI by removing the device, but if you are a keyboard ninja like me, the command is below. bluetoothctl remove mac_address
Put the headphones into pairing mode and run the following command bluetoothctl connect mac_address
After that, restart Bluetooth and see if the device connects automatically.
Step 4. Reinstall Bluetooth
This is the last resort if things don’t work out. Reinstallation can fix Bluetooth and other driver problems. BlueZ is the official Bluetooth stack for Linux. To reinstall Bluetooth, we need to reinstall the BlueZ package. To do this, use the following command. sudo apt reinstall bluez
Read: How to uninstall an application in Ubuntu
After reinstalling Bluez, enable and start the Bluetooth service with the following command. sudo systemctl enable bluetooth.service sudo systemctl start bluetooth.service
Now it can help you fix Bluetooth device auto reconnection. In case this does not allow you to proceed to the next step.
Step 5. Script
If the steps above did not work for you, we are in the same position. While about to ditch this article entirely, I came across a Python script on GitHub called bluetooth-autoconnect. This is a Python script that automatically connects to all paired and trusted Bluetooth devices. However, the script is not available for installation directly into the Flatpak or Apt repository. Hence, we need to manually load 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 loaded, we need to move the service and scripts to their respective location before we start the service. In my case, I am using the systemd architecture, so the file destinations provided are applicable to distributions such as ArchLinux, Ubuntu, Debian, etc. sudo cp bluetooth-autoconnect / bluetooth-autoconnect.service / etc / systemd / system / sudo cp ‘/ home / pratik / bluetooth-autoconnect / bluetooth-autoconnect’ / usr / bin /
After we have successfully copied the service to the appropriate directories, let’s enable and start the service. To do this, use the following command. sudo systemctl enable bluetooth-autoconnect.service sudo systemctl start bluetooth-autoconnect.service
Now that we have the service running, it will try to reconnect to all paired and trusted Bluetooth devices. The only caveat when using this method is that you won’t be able to pair your Bluetooth device with other systems without disabling Bluetooth on your Linux computer. Because the device will always try to connect to your bluetooth device.
Visit GitHub with automatic bluetooth connection
Closing words
In this article, I have looked through dozens of forums and articles on the Internet. I’ve tried using udev scripts for PulseAudio and Bluez Manager, but neither of them was able to auto-connect. Therefore, I have excluded them from this article. In my journey with Linux systems, besides the lack of good professional applications, Bluetooth was the second biggest problem. I could never come to the conclusion that the problem is in the manufacturer’s driver or whatever, Linux hasn’t figured it out yet.
Tell me about your experience in the comments and we can work out a solution together.
Also Read: 7 Best Equalizer Apps for Android for All Music Lovers