Raspberry Pi

How to Pair an Apple Wireless Keyboard to Raspberry Pi

In Mac by Michael Allen3 Comments

The screen of my Macbook Pro was damaged recently, so it had to be replaced. That meant I would be without a computer for a couple of days (annoying). Luckily, I have a Raspberry Pi (RPI) and decided to use it temporarily. I connected a wired USB keyboard and mouse to the RPI, and everything worked as it should. However, the keyboard and mouse were clunky and difficult to use compared with my familiar Apple wireless keyboard and magic trackpad. I decided to use the Apple gear on the RPI. After some research and a fair bit of tinkering, I finally got both the Apple keyboard and trackpad paired to my RPI. Now I can show you how to connect an Apple wireless keyboard and trackpad to your RPI.

Table of Contents


    RPI doesn’t have Bluetooth built-in so you’ll need an adapter to connect to Bluetooth devices. I use this IOGEAR bluetooth 4.0 USB micro adapter. It works out of the box with Raspberry Pi 2.


    Add Bluetooth Support

    sudo apt-get install bluetooth -y
    This command installs applications to help you detect and configure Bluetooth devices for your RPI.

    Pair the Apple Wireless Keyboard

    Now that Bluetooth is enabled, let’s see whether your USB adapter has been recognized by the system.
    sudo hcitool dev
    hcitool dev
    The output confirms the system has detected a bluetooth device – the USB adapter, and has named this device “hci0″.

    Next, let’s put the wireless keyboard in discovery mode so it can be found by the RPI.

    1. Press the On/Off switch and hold for 2 seconds before releasing it (to power off the keyboard).
    2. To force the keyboard into discovery mode press the On/Off switch and hold until the green LED begins blinking. Now it’s ready to be detected, paired, and connected by other Bluetooth devices.

    With the keyboard in discovery mode scan for any nearby Bluetooth devices.
    sudo hcitool scan
    hcitool scan
    The output says the system detected a Bluetooth keyboard and named it 04:DB:56:D1:DB:56 using its Mac address.

    Now that the keyboard is recognized we can pair it with the USB adapter.
    sudo bluez-simple-agent hci0 04:DB:56:D1:DB:56
    bluez simple agent Apple wireless keyboard
    You’ll be asked to enter the PIN code. Using the wired keyboard, type “0000” and press enter; now type “0000” and press enter on the wireless keyboard (while it’s in discovery mode). This sequence allows the adapter and keyboard to establish a persistent connection (by matching the PIN code you enter on each device).

    Next, you need to register the wireless keyboard as a trusted device so it will be automatically recognized and trusted each time the system boots.
    sudo bluez-test-device trusted 04:DB:56:D1:DB:56 yes

    Finally, connect the wireless keyboard to your RPI.
    sudo bluez-test-input connect 04:DB:56:D1:DB:56

    Pair the Magic Trackpad

    The process of pairing Apple’s magic trackpad is the same as pairing the keyboard. When you’re asked to enter the PIN code, type “0000” then press enter. Once the trackpad is paired you can register the trackpad as a trusted device and connect to it using the same commands you used to configure the keyboard.


    That’s it, if you have any questions, leave them in the comment area below.

    Images credit: Catherine Nurse


    1. Thank you for sharing.

      My case should be different though, I installed Raspberry Pi OS on my RPI 4 8GB, and I have been trying to pair an Apple Magic Mouse which I bought off Aliexpress.

      Anyways, I followed the commands and I can see Apple Magic Mouse when I hit the command $sudo hcitool scan.

      However the terminal says there’s no command when I hit $sudo bluez-simple-agent hci0 Macaddress. What should I do?

      I’d like to use the mouse on RPI OS.

      Anyone can help me out? Thanks in advance

    2. Hey! Great tutorial and so helpful. I am trying to use the same process on a RPI 3B with an Apple Magic Mouse and running into “command not found” after it discovers the device in the scan. Any tips?

    3. You write about an USB adapter to be recognized, but, as completely newbie, what is the USB adapter?

    Leave a Comment