- Pairing Bluetooth headphones in command line
- 6 Answers 6
- For Ubuntu Users
- Connect your headphones to Bluetooth in a robust manner.
- (If no sound) Configure your computer to output to your headphones
- How to Set Up Bluetooth in Linux
- Content
- How to Set Up Bluetooth on Your Linux Machine
- How to Install Bluez
- How to Install Blueman
- Enable Bluetooth
- Connect to Devices Using Blueman
- Set up Bluetooth Devices in GNOME Linux
- Connect to Bluetooth Devices in KDE Plasma
- Set Up the Bluetooth CLI Utility in Linux
- Frequently Asked Questions
- I have a Bluetooth USB Dongle that cannot pair with any device. Is my computer broken?
- How can I set up my phone through Bluetooth if it does not recognize my Linux machine?
- Is it possible to fix the audio skipping with Bluetooth headphones?
Pairing Bluetooth headphones in command line
How do you pair bluetooth headphones without using the GUI? I don’t know how to. I found different method on the internet but nothing works. I can actually see my headphones with the command : hcitool scan then i try to connect with : hcitool cc 00:00:00:00:00:00 and hcitool auth 00:00:00:00:00:00 I haven’t received an error message but my headphones are not working. thanks for your time.
6 Answers 6
- if you don’t know the MAC do : bt-device -l | grep
- now that you have the MAC connect with: bluetoothctl connect
Now put this in your profile:
alias headphones="until bluetoothctl connect ; do echo . ; sleep 1; done"
** MAC HERE will be the MAC you found in previous steps
It might fail a few times because of bt connectivity and latency of connections but it works after 3 tries for me.
I never solved the UI bluetooth manager issue but I got my BT device to connect through the cli (aka terminal).
- Scan for pairable BT devices: this will help you obtain the MAC address of your device. The device has to be in pair mode.
- Once you’ve found your device, copy the MAC address.
- Now you can attempt connecting (replace Xs with the copied MAC at step 3):
bluetoothctl connect XX:XX:XX:XX:XX:XX
You can get the list of bluetoothctl commands by typing:
Install it by running sudo apt-get install bluez-tools .
Find the MAC address of your device with bt-device -l and connect to it with bt-audio -c 00:00:00:00:00:00 .
The BT-audio program is not yet installed. You can install it by typing sudo apt-get install bluez-tools. I tried to remove and install bluez-tools but the problem is still there.
I’m on ubuntu 19.04 and executing the following worked for me:
sudo bluetoothctl where $DEVICE_MAC_ADDRESS is the mac address of the bluetooth device.
To find my device’s mac address I used bt-device -l
Both bluetoothctl and bt-device commands were already pre-installed on my system.
Hope this can help someone! 😉
To connect to a bluetooth headset, this worked for me.
I made sure bluetoothd was running.
I did: bluetoothctl devices
This gave the name and address of my bluetooth device.
I did: bluetoothctl connect
I saw: «Connection successful».
$ bluetoothctl devices Device B8:AD:3E:7B:5E:D2 LG HBS750 $ bluetoothctl connect B8:AD:3E:7B:5E:D2 Attempting to connect to B8:AD:3E:7B:5E:D2 [CHG] Device B8:AD:3E:7B:5E:D2 Connected: yes Connection successful the script I now use is simply: bluetoothctl connect B8:AD:3E:7B:5E:D2
For Ubuntu Users
Connect your headphones to Bluetooth in a robust manner.
We will use the bluetoothctl command-line utility:
- Important: Make sure your device is bluetooth discoverable by pressing some button on the device.
- Find the bluetooth device’s MAC-address by running $bluetoothctl scan on .
- This command will start discovering your devices and you need to spot your device’s mac address in the output. My device is called «Avi Ear» and it was found in the line:
- [CHG] Device 4C:87:5D:9E:04:B8 Name: LE-Avi Ear
- Important: Before running the script, make sure your device is bluetooth discoverable by pressing some button on the device.
#!/bin/bash # remove headphones and start fresh bluetoothctl remove 4C:87:5D:9E:04:B8 # turn bluetooth off bluetoothctl power off # turn blutooh on bluetoothctl power on # scan for devices for 15 secs so that our device gets discovered. timeout 15s bluetoothctl scan on # pair with headphones bluetoothctl pair 4C:87:5D:9E:04:B8 # trust headphones bluetoothctl trust 4C:87:5D:9E:04:B8 # connect to headphones bluetoothctl connect 4C:87:5D:9E:04:B8
- Finally, you should see headphones in the «Connected» state in Bluetooth Settings. For example, as you can see in the image below, «Avi Ear»(Name of my headphones) is «Connected».
(If no sound) Configure your computer to output to your headphones
Even though my headphones were shown as connected, I did not hear any sound. To hear sound you need to:
- Open the PulseAudio Volume Control App. This came preinstalled with Ubuntu for me, but you should be able to find easy instructions to install if you don’t have it.
- Go to the Configuration tab and make sure you have all other devices turned off except your headphones like this:
You should now be able to hear sounds from your headphones now.
How to Set Up Bluetooth in Linux
With the increasing prevalence of Bluetooth peripherals such as mice, keyboards, and headsets, it can be difficult to imagine using the wired versions of these devices sometimes. On some Linux distributions, Bluetooth is set up perfectly for you straight out of the box. Distributions like Ubuntu and Elementary make it easy for you to get Bluetooth set up and working on your machine. However, other distributions like Fedora and Arch Linux require you to do some setup before you’re able to fully enjoy the benefits of Bluetooth on your machine. Here is how you can set up Bluetooth in Linux.
Content
How to Set Up Bluetooth on Your Linux Machine
The steps will vary a little across distributions, but the basic steps are the same. If your distribution doesn’t already have Bluetooth set up for you, you will first need to install Bluez , which contains the driver stack for Bluetooth adapters as well as utilities for the CLI administration of Bluetooth.
After installing Bluez , you may need to install a Bluetooth manager. Some desktop environments have built-in Bluetooth managers. For example, KDE Plasma has the KDE Bluetooth client. Gnome also has a built-in client. If you are using a desktop environment that doesn’t have a built-in client, you can install the Blueman client.
How to Install Bluez
Below are instructions on how to install Bluez on a few different distributions.
Debian and Ubuntu
With OpenSUSE, you have to install bluez with the Open Build Service.
sudo dnf install bluez bluez-tools
sudo pacman -S bluez bluez-utils
Other Package Managers
Bluez works with all Linux distributions. If you have a different package manager than the distributions above, have no fear. You will just need to search for bluez in your package manager, then install everything that includes the term bluez.
How to Install Blueman
Find out how to install Blueman on various Linux distributions below.
Debian and Ubuntu
sudo zypper install blueman
Other Distributions
To install Blueman on your Linux distributions, you should search the package manager in the distribution being used for Blueman, then install all of the relevant packages.
Enable Bluetooth
After installation, you will need to activate and start the Bluetooth service. If you are using a Bluetooth dongle, you will first have to run the following command:
To enable the Bluetooth service, run the following command:
sudo systemctl enable bluetooth.service
To start the Bluetooth service, use this command:
sudo systemctl start bluetooth.service
After doing this, you’ll be able to start using Bluetooth on your system.
Connect to Devices Using Blueman
The connection process will vary depending on the desktop manager you’re using. However, we show how it’s done using Blueman since it’s fairly representative of the process across the board.
To connect to a device, open “Bluetooth Manager” in your applications and hit search. Make sure that the device you want to connect to is discoverable. When you see it in the device list, right-click on it and hit “Connect.” You may have to enter a passcode, but this information will be in the user’s manual of your device.
Set up Bluetooth Devices in GNOME Linux
Gnome comes with Bluetooth support from the start, and you can easily set up Bluetooth devices without installing any other tools.
- Click on the status icons on the top-right corner of your screen. Doing this will bring up a small menu where you can choose how your machine connects to the network.
- Click on the “Bluetooth” entry to bring up a drop-down menu where you can choose to toggle Bluetooth or access the appropriate settings for it. Choose to access the Settings.
- The Bluetooth Settings window will display all the devices that you can connect to. In this example, I can select my phone to pair it with my machine.
- GNOME will display a window showing a six-digit PIN that you need to match with your device to ensure that you are pairing the right devices together.
One important thing to note, however, is that the six-digit PIN will only show up on non-peripheral devices, as GNOME will automatically pair with any Bluetooth keyboard and headphones.
Connect to Bluetooth Devices in KDE Plasma
It is also possible to set up Bluetooth out of the box through the Plasma desktop in Linux.
- Click the Bluetooth icon in the lower-left corner of your screen to bring up a small menu where you can configure how Bluetooth works in your machine.
- Plasma will start its Bluetooth discovery program and search for every active nearby device and will list all found devices in a small window.
- Select your device and press “Next” to start the Bluetooth pairing process. Plasma will display a small window with a six-digit PIN that you need to match with your device.
Set Up the Bluetooth CLI Utility in Linux
It is also possible to connect a device through a dedicated Bluetooth CLI utility, a program that comes with Bluez that allows you to pair and control devices straight from your command line. It can be especially useful for devices that do not have a display, such as Raspberry Pi.
- Run the bluetoothctl program to load the Bluez CLI utility. This will change your prompt to [bluetooth]# .
- Tell the transmitter to scan for any active Bluetooth device in the area by running these two commands:
- Look for the device you want to pair with your computer by telling the transmitter to list all the devices that it detected during the scan:
- Use the MAC address of your device to pair it with your computer by running these two commands:
pair [MAC address] connect [MAC address]
One important thing to note, however, is that unlike the methods described above you need to type the PIN displayed on the device.
Frequently Asked Questions
I have a Bluetooth USB Dongle that cannot pair with any device. Is my computer broken?
No! This is most probably due to either incompatible or unsupported hardware. While Linux supports most Bluetooth devices, there are still some generic models that will not work under Linux. One way to deal with this issue is to use receivers that have chips that you know will work.
How can I set up my phone through Bluetooth if it does not recognize my Linux machine?
By default, your phone should be able to see your Linux machine if you have Bluetooth enabled on both devices. One reason your phone will not see your Linux machine may be that it is not discoverable.
One way to fix this is by telling bluetoothctl to force your computer to be discoverable by running the following command: sudo bluetoothctl discoverable on .
Is it possible to fix the audio skipping with Bluetooth headphones?
Yes! To fix this, make sure that the Bluetooth receiver is the only device in a particular USB bus. For example, you should not plug the headphones receiver into a USB hub, as it will share the same data line with other USB devices.
This is partly due to how Linux manages data through USB, as well as how PulseAudio interprets that same data. Some USB peripherals such as mice and keyboards tend to crowd the USB bus, leaving the audio receiver waiting for those peripherals to finish which, in turn, stutters the audio.
Image credit: Unsplash, altered by Ramces Red. All screenshots by Ramces Red
Ramces is a technology writer that lived with computers all his life. A prolific reader and a student of Anthropology, he is an eccentric character that writes articles about Linux and anything *nix.
Our latest tutorials delivered straight to your inbox
- This command will start discovering your devices and you need to spot your device’s mac address in the output. My device is called «Avi Ear» and it was found in the line: