Disabling Internal Keyboard on a Macbook and Linux

Welcome! This is my actual first post on this site. Allow me to preface it a bit, as I feel it’s a little necessary. Back in 2015, I took it upon myself to purchase a Macbook Pro. I’ve been a Linux enthusiast going on 15 years now, and the appeal of macOS was a Unix environment with proprietary software support. Well, about two years in, the keyboard started to malfunction. Keys either stick, or don’t work at all. I also really dislike the direction Apple has taken macOS in, so I’ve found myself back on Linux. This still leaves me with the keyboard problem, though. This is where driver unbinding comes in. This allows us to essentially tell the kernel to ignore the device. Coupled with a systemd service, we can get a solution that disables the keyboard on every boot.

The Bash

#!/bin/bash
for name in /sys/bus/hid/drivers/apple/*/*/*/name; do device=$(cut -d/ -f7 <<<"$name"); [ "$device" != "*" ] && printf "%s" "$device" > /sys/bus/hid/drivers/apple/unbind; done

This script queries your Apple HID drivers for the keyboard’s ID, and outputs it to file named “unbind” under the Apple HID driver directory.

Setting Everything Up

This part is rather simple. Just follow it to the letter, and after rebooting, your keyboard should be disabled!

First, we need to create the script that will run at boot. You can use any editor of your choosing if you don’t like vim.

$ sudo vim /usr/bin/disable-kb
$ sudo chmod +x /usr/bin/disable-kb

Then, we need to create our systemd service and enable it.

$ sudo vim /etc/systemd/system/disable-kb.service
     [Unit]
     Description = Disables internal keyboard

     [Service]
     WorkingDirectory= /usr/bin/
     ExecStart= /usr/bin/disable-kb

     [Install]
     WantedBy=multi-user.target

$ sudo systemctl enable disable-kb.service

And that’s it! Reboot, and your keyboard will no longer respond to any inputs. In fact, it won’t even show up as an available device. Feel free to run lsinput, and be amazed.

Page Content