43

Is there a way to pair a device in linux without requiring a pin(for testing purposes so I need it to be done w/out human interaction, assuming you have root access)?

bluez-simple-agent seems to require a pin except with some simple devices such as mice.

AjayKumarBasuthkar
  • 2,885
  • 2
  • 23
  • 27
Roman A. Taycher
  • 18,619
  • 19
  • 86
  • 141

7 Answers7

34

Entering a PIN is actually an outdated method of pairing, now called Legacy Pairing. Secure Simple Pairing Mode is available in Bluetooth v2.1 and later, which comprises most modern Bluetooth devices. SSPMode authentication is handled by the Bluetooth protocol stack and thus works without user interaction.

Here is how one might go about connecting to a device:

# hciconfig hci0 sspmode 1
# hciconfig hci0 sspmode
hci0:   Type: BR/EDR  Bus: USB
BD Address: AA:BB:CC:DD:EE:FF  ACL MTU: 1021:8  SCO MTU: 64:1
Simple Pairing mode: Enabled
# hciconfig hci0 piscan
# sdptool add SP
# hcitool scan
    00:11:22:33:44:55    My_Device
# rfcomm connect /dev/rfcomm0 00:11:22:33:44:55 1 &
Connected /dev/rfcomm0 to 00:11:22:33:44:55 on channel 1
Press CTRL-C for hangup

This would establish a serial connection to the device.

Paul Poulsen
  • 517
  • 1
  • 4
  • 9
25

follow steps (CentOs):

  1. bluetoothctl
  2. devices
  3. scan on
  4. pair 34:88:5D:51:5A:95 (34:88:5D:51:5A:95 is my device code,replace it with yours)
  5. trust 34:88:5D:51:5A:95
  6. connect 34:88:5D:51:5A:95

If you want more details https://www.youtube.com/watch?v=CB1E4Ir3AV4

hao ran
  • 251
  • 3
  • 4
  • Thanks for answer. Is it possible to do all of that from bash script? (maybe using other tool) – OlegWock Jun 03 '18 at 18:04
  • 3
    This is the solution I keep seeing, but for me no PIN is displayed and the pairing ends up canceling... – helmesjo Jan 07 '19 at 22:15
  • it asks me for a pin which i don't have on headphones. – chovy Jan 23 '21 at 06:01
  • Great. Got initially connected, but got `[CHG] Device 04:52:C7:7E:7A:F6 Connected: no` immediately after. After running `trust` and `connect` it worked. Thanks. – Michael Thelin Jan 10 '22 at 19:15
11

Try setting security to none in /etc/bluetooth/hcid.conf

http://linux.die.net/man/5/hcid.conf

This will probably only work for HCI devices (mouse, keyboard, spaceball, etc.). If you have a different kind of device, there's probably a different but similar setting to change.

Eric
  • 3,142
  • 17
  • 14
  • got an answer for the 2020s? `hcid.conf` went away, and if I put `Security=none` in `main.conf` then `bluetoothd` complains. – Phlip Dec 19 '22 at 16:40
9

This worked like a charm for me, of-course it requires super-user privileges :-)

# hcitool cc <target-bdaddr>; hcitool auth <target-bdaddr>

To get <target-bdaddr> you may issue below command:
$ hcitool scan

Note: Exclude # & $ as they are command line prompts.

Courtesy

Dallas
  • 2,217
  • 1
  • 13
  • 13
AjayKumarBasuthkar
  • 2,885
  • 2
  • 23
  • 27
7

For Ubuntu 14.04 and Android try:

hcitool scan #get hardware address
sudo bluetooth-agent PIN HARDWARE-ADDRESS

PIN dialog pops up on Android device. Enter same PIN.

Note: sudo apt-get install bluez-utils might be necessary.

Note2: If PIN dialog does not appear, try pairing from Android first (will fail because of wrong PIN). Then try again as described above.

Jack Miller
  • 6,843
  • 3
  • 48
  • 66
2
~ $ hciconfig noauth

This should do the trick (I'm using bluez 5.23 and there's no more simple-egent and blue-utils). However, I'm trying to look for a way to make changes hciconfig permanent because after power out and then power on, authentication is needed again. So far, the changes in hciconfig still stays the same when you reboot it. it reverts back only when power out. If anybody has found a way to make hciconfig permanent, do let me know!

Jamal
  • 763
  • 7
  • 22
  • 32
Darren Ng
  • 31
  • 1
0
~ $ hciconfig noauth

It worked for me in "Linux mx 4.19"

The exact steps are:

1) open a terminal - run: "hciconfig noauth"
2) use the blueman-manager gui to pair the device (in my case it was a keyboard)
3) from the blueman-manager choose "connect to HID"

step(3) is normally asking for a password - the "hciconfig noauth" makes step(3) passwordless

Jaimil Patel
  • 1,301
  • 6
  • 13