I have a bluetooth keyboard for my HTPC. I pair it with my computer via bluetooth, and it works fine. However, when I turn off the keyboard or my computer, it has to connect again (which requires me entering a passcode on the computer and keyboard) when I turn them back on. I've looked through many forums and through that I have found that I'm missing some seemingly vital bluetooth files:




In the instructions that I've found online so far, I must change certain lines in any of these files. I am unable to, since they do not exist.

Am I missing a dependency or something? I've also tried installing Blueman but that didn't help at all.

I'm running Ubuntu 10.10 (Maverick).

Original post: http://ubuntuforums.org/showthread.php?t=1643386&highlight=bluetooth

5 Answers 5


This answer comes from a tutorial written by Andrew Martin on thetechdepo.com. See the link below for the original post, however this is a complete rewrite. It is written specifically for an apple keyboard, however I have used it for multiple devices so it is not apple, or keyboard specific. Simply follow the instructions and you will have any bluetooth device auto connect in Ubuntu.

Go to System Settings > Bluetooth and follow the instructions to add your newly connected bluetooth device.

Follow the instructions and enter the pin when requested, then after the device is connected and working, power off the device. Now onto the auto connect part.

Open your terminal and enter the following commands:

$ killall bluetooth-applet 
$ sudo /etc/init.d/bluetooth restart 
$ sudo hcitool dev

The last command will display the output for your device such as:

    hci0    00:00:00:00:00:00

Install a new package to allow you to connect bluetooth via the command line.

$ 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:

$ hcitool scan        
Scanning ...
    AA:BB:CC:DD:EE:FF   Bluetooth Device Name
$ sudo hidd --connect AA:BB:CC:DD:EE:FF

Now we have to create a startup file to auto connect the device when the pc starts. Via the terminal...

$ 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.

#! /bin/bash


while (sleep 1)
connected=`sudo hidd --show` > /dev/null
if [[ ! $connected =~ .*${address}.* ]] ; then
sudo hidd --connect ${address} > /dev/null 2>&1

Now create a new startup file. Substitute "keyboard" for whatever device name you choose. This is simply the name of the file.

$ sudo gedit /etc/init.d/keyboard

Paste the following, which tells your Ubuntu to run the file you just created at startup.

/home/username/.keyboard.sh &

exit 0

Now set both files permissions to executable via the terminal.

$ sudo chmod +x /etc/init.d/keyboard
$ chmod +x ~/.keyboard.sh
$ sudo update-rc.d keyboard defaults

Restart your computer and your device should auto connect and be working without you having to do anything.

I hope this helps a few people, it took me a long time to find a solution to my problem and I wanted to cement this tutorial a little deeper into the web.

The original link can be found here.

  • I believe that hidd is now deprecated as of bluez 4.0 in favour of udev, according to /usr/share/docs/bluez/NEWS.Debian.gz but I can't find any documentation on how to do it without bluez-compat. Commented Jun 20, 2013 at 5:18
  • Best answer, but couldn't install hidd tool on Ubuntu 22.04. For modern Linux: CONNECTED=$(bluetoothctl info $MAC_ADDRESS | grep Connected | grep yes). Then if [[ -z "$CONNECTED" ]]; then... bluetoothctl connect $MAC_ADDRESS
    – d9k
    Commented Dec 31, 2022 at 18:58

I also tried ryandlf's answer by myself but found another easy setup which will eventually do the same work.

Main idea is that once the remote device is paired and trusted, hcitool spinq will initiate periodic inquiry which will let every available devices be connected.

First, initiate sudo Bluetoothctl -a and follow steps below. These are from ArchLinux wiki but proven to work same in Ubuntu as well.

[bluetooth]# power on
[bluetooth]# agent KeyboardOnly
[bluetooth]# pairable on
[bluetooth]# scan on

Last command will show all available (waiting for pairing) bluetooth keyboards like this.

Discovery started
[CHG] Controller 01:02:03:04:05:06 Discovering: yes

Note that address of your keyboard and continue with it.

[bluetooth]# pair 01:02:03:04:05:06
[bluetooth]# trust 01:02:03:04:05:06
[bluetooth]# connect 01:02:03:04:05:06
[bluetooth]# quit

Now put this simple script into /etc/init.d/keyboard

#! /bin/sh
sudo hcitool spinq
exit 0

Then execute these.

sudo chmod +x /etc/init.d/keyboard
sudo service keyboard enable
sudo update-rc.d keyboard defaults
sudo service keyboard start

That's it. Now whenever you turn your Bluetooth keyboard on, it'll be connected to your Linux automatically.

  • $ sudo update-rc.d keyboard defaults insserv: script keyboard is not an executable regular file, skipped! To solve, I performed sudo chmod +x /etc/init.d/keyboard. Then I performed sudo update-rc.d keyboard defaults. Received warning: insserv: warning: script 'keyboard' missing LSB tags and overrides.
    – orschiro
    Commented Oct 21, 2016 at 11:14
  • What about sudo service keyboard enable?
    – orschiro
    Commented Oct 25, 2016 at 7:36
  • Yes, you've done right with chmod +x.
    – Ch.Idea
    Commented Dec 4, 2016 at 6:02
  • LSB tags missing error can be ignored and not really important in this task. If you want to, search for it by googling and paste on top of the file. They're in simple form.
    – Ch.Idea
    Commented Dec 4, 2016 at 6:05

Since bluez 5.35 (September 2015), it should be enough to modify the configuration file /etc/bluetooth/main.conf by enabling AutoEnable=true.

To pair a new device from a terminal (assuming that 01:02:03:04:05:06 is the mac address of the device you're trying to pair):

$ bluetoothctl
# power on
# agent KeyboardOnly
# default-agent
# pairable on
# scan on
# pair 01:02:03:04:05:06
# trust 01:02:03:04:05:06
# connect 01:02:03:04:05:06
# quit
$ exit
  • Yeah the trust part is what made the difference for me being able to autoreconnect on startup.
    – p1l0t
    Commented Aug 1, 2019 at 16:39

I have bought a bluetooth keyboard, and landed on this page here, and tried what ryandlf and what Ch.Idea suggested. It didn't work. After some analysis and trials, I found this combination:

First, as guys suggested, try to connect the device manually from GUI. Make sure it works. Then disconnect it, and switch off. We will start over manually then.

Get root privileges:



hcitool scan

and simultaneously press buttons or whatever on device, and make sure it is discovered. If discovered, it should print an address of it, e.g. 20:73:00:01:90:65, and a description of device, e.g. Bluetooth keyboard. Grab that address to clipboard.

Next, we are ready to connect. EVERYONE ALL OVER THE INTERNET SUGGEST HIDD, WHICH IS MISLEADING AS IT ISN'T PRESENT ANYMORE. That's why I couldn't make this work for so long... After looking at man of hcitool, I found plenty of useful commands, and no need to use dbus or whatever. So, to connect it, we issue:

hcitool cc 20:73:00:01:90:65

and that's it.

Experiments showed that it even reconnects automatically, when I temporarily switched the device off.


I also created a service, as guys suggested in other answers. First, I created a file /etc/init.d/keyboard, with this content:

#! /bin/sh
sudo hcitool cc 20:73:00:01:90:65
exit 0

Then, as root:

chmod +x /etc/init.d/keyboard
service keyboard enable
update-rc.d keyboard defaults
service keyboard start

That's it. Hope it helps.

Oh, and it's Debian 9.


I had a very similar issue with an Apple BlueTooth keyboard. I bought it because I loved the feeling of the keys. However, I could not keep it connected. The problem seemed to be in the keyboard identification. Once it was matched to an actual MAC computer, where it got an actual name, I no more had any issue with connecting it to Linux or Windows. My wife now uses it with no problem.

I don't know how this can be transposed in your situation, but this can be a starting point. From other friends, it seems that the device identification is the main issue here.

You must log in to answer this question.

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