Connect and Use Wireless USB and Bluetooth Mouse and/or Keyboard on Linux

Wainaina Gichuhi
4 min readMay 5, 2023

--

If you have just bought your new wireless USB Bluetooth Mouse and Keyboard combo, or just one of each, and you’re planning to use them on some Linux based OS, this tutorial is for you.

Wireless Bluetooth Mouse and Keyboard
Source: https://i.dell.com/is/image/DellContent/content/dam/ss2/product-images/peripherals/input-devices/dell/keyboards/km3322w/media-gallery/keyboard-mouse-km3322w-gallery-5.psd?fmt=pjpg&pscan=auto&scl=1&wid=4162&hei=2187&qlt=100,1&resMode=sharp2&size=4162,

Before buying, it’s important to check whether the manufacturer lists the devices as supported on your OS. This can be done by checking the wrapping box, the instructions manual, or via their website. If the manufacture does not include Linux as one of the supported OSes, do not panic, there might be a workaround for you. If the devices work on Windows or Mac OS, they most probably will work on Linux with little issues.

Devices” in this context refer to either or both a wireless USB or Bluetooth mouse and/or keyboard.

Mode” is this context refers to both wireless USB and bluetooth modes for mouse and/or keyboard.

Wireless USB Mode

For those with only wireless USB mode, this is the only section you need.

Connecting the devices on wireless USB mode is easy; just plug in the adapter and the mouse and/or keyboard should begin working (the drivers are already loaded in the kernel unlike Windows).

If you are having battery longevity issues on wireless USB mode, these are the possible causes and solutions.

Bluetooth Mode

Prerequisites

  1. Ensure your Bluetooth adaptor is turned on.
  • You can check if the Bluetooth adapter is turned on by running the following command:
rfkill list
  • Look for the Bluetooth device in the output of the command. If the Bluetooth adapter is turned on, it should show as “unblocked”.
  • If you do not see the Bluetooth device listed or it is blocked, you can turn it on using the following command:
sudo rfkill unblock bluetooth
  • Alternatively, you can restart the bluetooth service using this command:
sudo systemctl restart bluetooth.service

2. Ensure you have bluez and either bluez-utils or bluez-utils-compact installed. You can search the store or use your package manager.

You can use the GUI or Terminal to connect bluetooth Keyboard or Mouse.

1. Connect via GUI

  • Launch bluetooth manager (blueman). Some distros have it installed by default. Launch it by searching for Bluetooth manager in your menu. If it’s not installed, searching your store or package manager for blueman.
Bluetooth Manger (blueman)
Bluetooth Manger (blueman)
  • Ensure your bluetooth keyboard or mouse is in pairing mode. Follow the instructions for your device (check the printed or online manual).
  • Select adaptor > search
Search device
Search bluetooth device
  • Your keyboard or mouse (if in pairing mode) should appear in the list.
  • Right click on the bluetooth device and select `Pair`.

For bluetooth keyboards, you will/may be required to enter a pairing code displayed in pop up window or notification then press enter.

  • Right click on bluetooth device and select `Connect` to connect the device.
  • Right click on bluetooth device and select `Trust` to trust device. Trusting a device ensures that it reconnets automatically after a reboot or when turn off and on.
  • Repeat the above procedure for the another bluetooth mouse/keyboard.

2. Connect via Terminal

To connect your bluetooth mouse or keyboard via terminal,

  • Put your mouse or keyboard in pairing mode (the instructions are provided by the device manufacturer).
  • Type the command bluetoothctl and press enter
  • In the bluetoothctl prompt, type the command scan on and press enter. You should see available bluetooth devices and their MAC address listed. Note your keyboard or mouse and copy the MAC address.
Available devices and their MAC addresses
Available devices and their MAC addresses
  • Type pair MAC and press enter.

If the device is a keyboard, you’ll see a pairing code to input on the bluetoooth keyboard. Input it on the bluetooth keyboard you are pairing and press enter.

  • Type connect MAC and press enter.
  • Type trust MAC and press enter. Trusting a bluetooth device ensures that it reconnets automatically after a reboot, wake or when turned on.

Remember to replaceMACwith YOUR keyboard or mouse MAC address. In the scan output above, my bluetooth mouse MAC address is 6C:5D:63:94:7A:FB.

Bluetooth Low Energy (BLE) Devices

Some Bluetooth Keyboards and Mouse provide Bluetooth Low Energy (BLE) modes. However, not all adapters support BLE mode.

  • To check if your Linux system (adaptor) supports Bluetooth Low Energy (BLE), type the following command and press Enter:
sudo hcitool lescan
  • If you see a list of nearby Bluetooth Low Energy devices in the terminal, your Linux system supports BLE.
  • If you receive an error message that says “Set scan parameters failed: Operation not supported”, it means that your adaptor does not support Bluetooth Low Energy mode.

BLE devices might appear when using bluetoothctl scan on. However, pairing or connecting in this mode becomes a problem if the adaptor does not support Bluetooth Low Energy.

And that’s it!

Hopefully, your wireless USB or bluetooth keyboard and/or mouse should be working like a charm.

I’d like to hear from you, did the tutorial work for you? If not, where are the challenges?

Regards.

--

--