18

I've been trying to pair up my bluetooth keyboard with my computer after reinstalling from a standard ubuntu 12.04 to a minimal install.

In the minimal install I have no gui, so I've been trying to use the various command line tools available, but I can't figure out how the pairing is supposed to go. Pairing when I had a gui worked flawlessly.

I've asked for help here: http://ubuntuforums.org/showthread.php?p=12234695

No one has replied but a lot of details of my situation is available there.

How is one supposed to pair bluetooth devices from the command line?

2 Answers 2

18

Pair a new device

In Bluez4 install the bluez Install bluez package to be able to pair a device from the command line with bluez-simple-agent (Bluez5 will provide the bluetoothctl command):

bluez-simple-agent hci# xx:xx:xx:xx:xx:xx

Replace # with the Bluetooth adapter number (e.g. hci0) and xx:xx:xx:xx:xx:xx with the MAC of our Bluetooth device.

  • To get the number of our adapter we may issue:

      hciconfig
    
  • The MAC of devices can be scanned for with the following command:

      hcitool scan
    

The Bluetooth device should be in pairing mode of course. Enter the pin code when asked to pair the device.


Remove a paired device

If we already had paired a device and need to remove it from the database (e.g. for re-pairing) we may do so with

bluez-simple-agent hci# xx:xx:xx:xx:xx:xx remove

Note for keyboards (or mice): Until the Bluetooth keyboard is paired we may need to enter the PIN using an additional wired keyboard. See with the manual of your keyboard how the pairing is done (some expect PIN in computer first, some in keyboard first. Some may have a fixed PIN).

After pairing, we connect the keyboard with:

sudo bluez-test-input connect xx:xx:xx:xx:xx:xx 

To allow auto-connection after a reboot we can add the device to the trusted devices:

sudo bluez-test-device trusted xx:xx:xx:xx:xx:xx yes
7
  • 1
    Very useful and tested to work.
    – nanofarad
    Commented Sep 12, 2012 at 19:31
  • I very much appreciate the answer, unfortunately I've done that exact thing without getting the keyboard to work. When pairing using the gui the computer used to suggest a pin which I then wrote using the keyboard. This is not what happens using bluez-simple-agent. It instead asks for a pin. I don't have a static pin for the keyboard, and suppling the one I give to bluez-simple-agent through the keyboard does nothing to aid the pairing.
    – azzid
    Commented Sep 12, 2012 at 22:21
  • 2
    After pairing, you also need bluez-test-input connect xx:xx:xx:xx:xx:xx to be able to use the paired keyboard. (doesn't help azzid if stuck on pairing, but for other readers of this question) Commented Nov 3, 2013 at 2:41
  • Your comment is a good addendum to the really nice answer which shall be extended with that information. Commented Nov 3, 2013 at 3:17
  • hcitool scan is not scanning any device
    – RahulG
    Commented Apr 11, 2015 at 3:28
0

After searching a lot I've found two solutions. One is bluetoothctl which is performs exactly what you are looking for. You can do almost anything from command line :) Because I'm lazy and my memory is still on HDD I need some applet as well, so I've installed bluedevil on my mate desktop :) it is working except scanning, but it is fine like this

1
  • Since it's been more than two years I no longer have the setup to verify your suggestion, but thanks anyway! =)
    – azzid
    Commented Oct 7, 2014 at 17:20

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .