Note: This guide uses programs specific to Ubuntu 10.04 (Lucid Lynx) and newer. For older versions of Ubuntu, please refer to this Ubuntu Wiki page.
Sometimes the Ubuntu bluetooth stack can behave erratically and prevent you from connecting your Apple Bluetooth Keyboard (or other bluetooth device). The normal procedure for connecting your bluetooth keyboard involves the following steps:
First, make sure the bluetooth applet is running by looking for the bluetooth icon on your panel:
![]()
If it is not running, press ALT+F2, enter bluetooth-applet in the dialog box, and click Run to start it:

Second, click on the icon and select the "Set up new device..." link. This will bring up a window which gives you some instructions. Click Forward and then select your Apple Bluetooth Keyboard. Note: your keyboard must be turned on during this step:

Proceed through the installer, entering the PIN that it gives you on the keyboard and hitting the Enter key when done. If all goes well, your keyboard should start working shortly thereafter. If it does not work, or you receive messages on the computer telling you to enter the PIN from the device, you will need to perform additional steps. Power off your keyboard and then open the Terminal program (gnome-terminal) and enter the following commands:
1 2 3 |
$ killall bluetooth-applet $ sudo /etc/init.d/bluetooth restart $ sudo hcitool dev |
The last command should return output for your device, something like the following:
Devices: hci0 00:00:00:00:00:00
Once this is done, you will need to install a new package to allow you to connect to the device via the command line. To do so, enter the following command:
$ sudo apt-get install bluez-compat
Once this has completed, you will now have hidd program installed. At this point, turn on your keyboard and enter the following command. It will output the MAC Address of your keyboard, which you will need to copy and paste into the subsequent command, as seen below:
1 2 3 4 |
$ hcitool scan Scanning ... AA:BB:CC:DD:EE:FF Apple Wireless Keyboard $ sudo hidd --connect AA:BB:CC:DD:EE:FF |
Give it a couple seconds and then try typing on your keyboard. Hopefully, it will now be connected and working. To automate this process so your keyboard will connect automatically when you start your computer, create a new file by running this command:
$ gedit ~/.keyboard.sh
Enter the following text, substituting AA:BB:CC:DD:EE:FF with the hardware ID you saw above. Finally, save the file.
1 2 3 4 5 6 7 8 9 10 11 |
#! /bin/bash address="AA:BB:CC:DD:EE:FF" while (sleep 1) do connected=`sudo hidd --show` > /dev/null if [[ ! $connected =~ .*${address}.* ]] ; then sudo hidd --connect ${address} > /dev/null 2>&1 fi done |
Then, create a new startup file:
$ sudo gedit /etc/init.d/keyboard
Paste the following into this file, which tells it to run the file that you just created at startup. Note, you must specify the entire path to your home directory. In this example, the username used is ubuntu:
1 2 3 4 |
#!/bin/sh /home/ubuntu/.keyboard.sh & exit 0 |
Now, set both files to be executable and then add the startup file to the list of startup programs:
1 2 3 |
$ sudo chmod +x /etc/init.d/keyboard $ chmod +x ~/.keyboard.sh $ sudo update-rc.d keyboard defaults |
Restart your computer and your keyboard should work immediately! If not, please post a question here or at Ubuntu Forums for more troubleshooting.




