This answer works for bluetoothd v5.35 - I assume that it will also work with earlier releases of bluetoothd v5.
- Pair with the device in linux
- Reboot
- Pair with the device in windows
- Extract the link key as described by thezeroth
- Turn off the BlueTooth device and reboot into linux
Make sure to have your device turned off when booting linux.
Otherwise it will try to connect to the device repeatedly with the old (and now invalid) link key. This might trigger anti brute-forcing measures rendering the device unreachable.
Go to the subfolder that is named after the device's address. You should find a file named 'info' there. Open that.
sudo nano /var/lib/bluetooth/XX:XX:XX:XX:XX:XX/YY:YY:YY:YY:YY:YY/info
In the [LinkKey]
section set the Key. Example:
Key=3E717C5B8735C1984B71636D7B941DEE
Now check the [General]
section and set
Trusted=false
Save, and restart bluetoothd:
sudo service bluetooth restart
When you turn on the device, a popup should appear, asking if you want to authorize the connecting bluetooth device. Of course you do!
If you extracted the link key from Mac OS you'll need to reverse the byte order of the key. Mac OS saves it in reverse endianness.
Clone this Github repository: https://github.com/kcolford/hidclient
git clone https://github.com/kcolford/hidclient
Edit the hidclient.c
and comment out #include <stropts.h>
(line number 105)
Build it
gcc -o hidclient -O2 -lbluetooth -Wall hidclient.c
List all input devices:
sudo ./hidclient -l
The output would look similar to this:
[severus@tux hidclient]$ sudo ./hidclient -l
List of available input devices:
num Vendor/Product, Name, -x compatible (x/-)
0 [0000:0005.0000] 'Lid Switch' (-)
1 [0000:0001.0000] 'Power Button' (+)
2 [0000:0001.0000] 'Power Button' (+)
3 [0001:0001.ab41] 'AT Translated Set 2 keyboard' (+)
4 [0000:0000.0000] 'HP Wireless hotkeys' (+)
5 [001f:0001.0100] 'PC Speaker' (-)
6 [0000:0000.0000] 'HDA Intel PCH Mic' (-)
7 [0000:0000.0000] 'HDA Intel PCH Headphone' (-)
8 [0000:0006.0000] 'Video Bus' (+)
9 [0000:0006.0000] 'Video Bus' (+)
10 [0000:0000.0000] 'HP WMI hotkeys' (+)
11 [0000:0000.0000] 'HDA Intel HDMI HDMI/DP,pcm=3' (-)
12 [0000:0000.0000] 'HDA Intel HDMI HDMI/DP,pcm=7' (-)
13 [0000:0000.0000] 'HDA Intel HDMI HDMI/DP,pcm=8' (-)
14 [0000:0000.0000] 'HDA Intel HDMI HDMI/DP,pcm=9' (-)
15 [0000:0000.0000] 'HDA Intel HDMI HDMI/DP,pcm=10' (-)
[severus@tux hidclient]$
If you want to expose keyboard (say) bluetooth,
sudo ./hidclient -e3 -x
-x
to disable it on host.
Note: If you get error related to SDP server, you might want to enable compat
to support some of the depreciated functions. For that, refer: https://askubuntu.com/a/814969/497359
Best Answer
The answers to this question give you the general idea, though a bit vague on the macOS side, so I'll spell out the procedure I used.
OS versions as follows. The file names and locations appear to be subject to change according to versions, so this is what worked for me.
I am assuming that you have a filesystem (USB key or whatever) that is at least read-write in MacOS and readable in Ubuntu.
The general idea is that when you pair a device to an OS, a unique link key is generated, which is necessary for authentication next time the pairing is active. You can transfer these link keys from MacOS pairings to Ubuntu pairings such that the pairings work in both OSes.
sudo defaults read com.apple.bluetoothd.plist LinkKeys
. This will give you output something like:Here
a0-99-9b-16-43-d2
is the MAC address of the bluetooth adapter on my system.Following that are the MAC addresses of devices that I have paired (
00-1f-20-47-e5-22
and04-0c-ce-3d-15-4d
and the link keys associated with those pairings (4d6b002f 37584c09 ee219365 b78ba03e
andfe998c62 4bb29a7c 40b2e670 10db71ed
respectively)./var/lib/bluetooth
. You should see a subdirectory entry for the bluetooth adapter MAC address, formatted likeA0:99:9B:16:43:D2
. Inside that you should see subdirectories for each device MAC address, like00:1F:20:47:E5:22
and04:0C:CE:3D:15:4D
. Inside those directories you will find files namedinfo
. Edit these files with your favourite editor:Key
entry. This key needs to be made the same as what you found in MacOS, but with some important formatting differences:You can achieve this as follows:
Edit these reformatted keys into the Key entry of the appropriate info files. Most likely
sudo
will be required.Update: The pairings seem to have persisted through upgrades on both MacOS and Ubuntu. I'm now running 10.13.6 and 18.04 respectively and have not yet had to redo this procedure.