Bluetooth keyboard

Posted on Tue 01 March 2016 in linux

Setting up a bluetooth keyboard in debian without using UI tools is a little bit tricky, but in the end it turns out as not too hard.

Installing the basic bluetooth packages

In the first step, the basic bluetooth package must be installed:

apt-get install bluetooth

The bluetooth service should automatically be started, so make sure that it is running correctly:

service bluetooth status

Pairing using CLI

In the next step, the bluetooth keyboard must be paired with the bluetooth controller in your PC. An easy way to pair the devices is to use the bluetoothctl command, which will provide a simple CLI interface to interact with the computer's bluetooth controller. Start the CLI as follows:


Make the bluetooth controller discoverable and pairable; then, activate the scan mode to discover the bluetooth keyboard:

[bluetooth]# discoverable on
[bluetooth]# pairable on
[bluetooth]# scan on

Enable the bluetooth discovery mode on the keyboard by clicking the corresponding pairing button. After a while, the bluetooth keyboard should appear in the CLI. Note the device ID of the discovered bluetooth keyboard:

[CHG] Controller xx:xx:xx:xx:xx:54 Discovering: yes
[NEW] Device xx:xx:xx:xx:xx:fe Logitech K810

Now, pair the keyboard with the bluetooth controller by using the discovered keyboard ID:

pair xx:xx:xx:xx:xx:fe

Additionally, mark the keyboard as trusted device:

trust xx:xx:xx:xx:xx:fe

Finally, connect the keyboard to the computer:

connect xx:xx:xx:xx:xx:fe

Check the correct connection using the info command

info xx:xx:xx:xx:xx:fe

Permanent pairing

The described pairing of the bluetooth keyboard with the computer will just last until the next reboot. To automatically pair the bluetooth keyboard on next startup, a simple udev rule can be created:

echo 'ACTION=="add", KERNEL=="hci0", RUN+="/usr/bin/hciconfig hci0 up"' > /etc/udev/rules.d/10-bluetooth.rules

On the next reboot, the bluetooth keyboard should be automatically connected to the computer. Note that it will take a while until the bluetooth connection will be setup, i.e. the bluetooth keyboard cannot be used in grub or during the boot process, but rather after the login screen is shown.