How to Manage Bluetooth in Ubuntu via CLI?
Managing Bluetooth devices from the command line in Ubuntu is a
powerful way to troubleshoot connectivity issues, automate pairings, or
manage headless server environments. This article provides a
comprehensive guide to using bluetoothctl, the built-in
interactive utility for controlling Bluetooth on Linux. You will learn
how to turn on your Bluetooth controller, scan for nearby devices, trust
and pair with them, and connect or disconnect devices seamlessly using
simple terminal commands.
Getting Started with bluetoothctl
Ubuntu includes a built-in command-line tool called
bluetoothctl which communicates directly with the BlueZ
Bluetooth protocol stack. To start managing your devices, open your
terminal and launch the interactive shell by typing:
bluetoothctlOnce inside, your terminal prompt will change to
[bluetooth]#. This indicates you are ready to issue
Bluetooth commands. To exit this interactive mode at any time, simply
type exit.
Powering On and Scanning for Devices
Before you can connect to a device, you need to ensure your local Bluetooth adapter is turned on and visible.
- Turn on the Bluetooth controller:
power on- Enable the agent: The agent manages the pairing process, including PIN codes and passkeys.
agent on
default-agent- Start scanning: Turn on discovery mode to find nearby Bluetooth devices.
scan onAs the scan runs, you will see a list of discovered devices scrolling
in your terminal. Each device will display its unique MAC address
(formatted like AA:BB:CC:DD:EE:FF) and its name. Note down
the MAC address of the device you want to connect to.
Pairing and Connecting a Device
Once you have identified the MAC address of your target device, you
can proceed with the pairing process. Replace
XX:XX:XX:XX:XX:XX with your actual device’s MAC address in
the following steps:
- Pair the device: This establishes a secure bond.
pair XX:XX:XX:XX:XX:XXNote: If prompted for a PIN code on your terminal or your device, enter it to complete the pairing. 2. Trust the device: Trusting a device allows it to reconnect automatically in the future without asking for permission again.
trust XX:XX:XX:XX:XX:XX- Connect to the device: Finalize the connection to start using your device.
connect XX:XX:XX:XX:XX:XXDisconnecting and Removing Devices
If you need to sever a connection or completely clear a device from your Ubuntu system’s memory, you can do so with these straightforward commands:
- Disconnect a device: Keeps the device paired but stops the active connection.
disconnect XX:XX:XX:XX:XX:XX- Remove a device: Unpairs the device completely and deletes its configuration.
remove XX:XX:XX:XX:XX:XX- Turn off Bluetooth: When you are finished, you can power down your local Bluetooth controller to save energy.
power off