How to Enable and Disable Your Laptop Keyboard in Linux
When you dock a laptop with an external USB keyboard, the built-in keyboard becomes a nuisance—it’s too easy to brush keys while typing and trigger unwanted input. Rather than disabling the keyboard at the BIOS level or physically disconnecting it, you can use the xinput tool to disable and re-enable it from within your Linux session.
Prerequisites
You’ll need:
xinputinstalled (included by default on most X11 desktop environments)- An external USB keyboard connected before disabling the laptop keyboard
- Access to a terminal or SSH session to re-enable if needed
If xinput isn’t installed, grab it from your distro’s repos:
# Debian/Ubuntu
sudo apt install x11-utils
# Fedora
sudo dnf install xorg-x11-utils
# Arch
sudo pacman -S xorg-xinput
Finding Your Keyboard IDs
First, list all input devices to identify your laptop keyboard:
xinput list
You’ll see output like this:
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ Logitech USB Mouse id=9 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Power Button id=6 [slave keyboard (3)]
↳ AT Translated Set 2 keyboard id=10 [slave keyboard (3)]
↳ HP WMI hotkeys id=12 [slave keyboard (3)]
The AT Translated Set 2 keyboard is almost always your built-in laptop keyboard. Note its ID (in this example, id=10). The Virtual core keyboard is the master device (typically id=3).
Automate finding the laptop keyboard ID:
LAPTOP_KB_ID=$(xinput list | grep 'AT Translated Set 2' | sed -n 's/.*id=\([0-9]*\).*/\1/p')
echo "Laptop keyboard ID: $LAPTOP_KB_ID"
Disabling the Keyboard
To disable the laptop keyboard, detach it from the master keyboard device:
xinput float <ID>
Replace <ID> with your laptop keyboard’s ID. For example:
xinput float 10
The float command detaches the device from its master, effectively disabling it. You should immediately stop receiving input from the laptop keyboard. Test by pressing keys—they won’t register.
Re-enabling the Keyboard
To bring the keyboard back online, reattach it to the master keyboard device:
xinput reattach <ID> <MASTER_ID>
For example:
xinput reattach 10 3
The keyboard becomes functional again.
Automated Scripts
Create a reusable script pair for convenience. Save this as disable-laptop-kb.sh:
#!/bin/bash
LAPTOP_KB_ID=$(xinput list | grep 'AT Translated Set 2' | sed -n 's/.*id=\([0-9]*\).*/\1/p')
if [ -z "$LAPTOP_KB_ID" ]; then
echo "Error: Could not find laptop keyboard"
exit 1
fi
echo "Disabling laptop keyboard (ID: $LAPTOP_KB_ID)..."
xinput float "$LAPTOP_KB_ID"
echo "Done. Keyboard disabled."
And enable-laptop-kb.sh:
#!/bin/bash
LAPTOP_KB_ID=$(xinput list | grep 'AT Translated Set 2' | sed -n 's/.*id=\([0-9]*\).*/\1/p')
MASTER_ID=3
if [ -z "$LAPTOP_KB_ID" ]; then
echo "Error: Could not find laptop keyboard"
exit 1
fi
echo "Enabling laptop keyboard (ID: $LAPTOP_KB_ID)..."
xinput reattach "$LAPTOP_KB_ID" "$MASTER_ID"
echo "Done. Keyboard enabled."
Make them executable:
chmod +x disable-laptop-kb.sh enable-laptop-kb.sh
Then run them as needed:
./disable-laptop-kb.sh
./enable-laptop-kb.sh
Desktop Environment Integration
You can bind these scripts to keyboard shortcuts in your desktop environment for one-key toggling:
GNOME/MATE: Settings → Keyboard Shortcuts → Custom Shortcuts
KDE Plasma: System Settings → Shortcuts → Custom Shortcuts
Xfce: Settings → Keyboard → Application Shortcuts
Important Notes
- The master keyboard device ID is usually
3, but verify withxinput listif the re-enable script fails. - Changes persist only during your X11 session. Rebooting resets everything.
- If you disable the keyboard without an external keyboard connected, you’ll need to SSH in or restart to recover.
- Some hybrid-sleep or hibernation events may require you to run the disable script again after resuming.
Alternatives
If you prefer permanent solutions, check your laptop’s BIOS settings—many allow disabling internal keyboards entirely. Alternatively, use your desktop environment’s accessibility settings under “Physical Keyboard” if available, though xinput is more reliable and reversible.

Thats nice,but not working for me, i use kali linux 2018.2 and i get this error
/root/laptopkb/laptopkb-get-id.sh: line 5: xinput: command not found
./laptopkb-disable.sh: line 7: xinput: command not found
The reason seems that you don’t have `xinput` installed in your system. You may need to install it first.
you will tell me how to install it? i google it and nothing
You may ask the question in kali linux communities. I am not a kali linux user.
Hiw to install or apply this script
I don’t know why xinput can’t find the internal keyboard.I’m on ubuntu 19.04.
The `xinput` may not work for Wayland which ubuntu 19.04 may use. This may be the cause.
You may try `evtest` to grab the events for the device, which “disables” the device for other processes.
Thanks
Thanks! It works great
My cats like to walk on the keyboard :P
Thank you! Because of soda spill, my laptop keyboard became troublesome. This script saved my work :-) Thank you for sharing!
Hiw to install or apply this script
Hi, I’m on Linux Mint 20.1
I don’t see see “AT Translated Set 2 keyboard id=……”
Trying since 2w to find a solution, till now unsuccessful.
Can you help?
Thx in advance!!
This is my output:
xinput –list
⎡ Virtual core pointer id=2 [master pointer (3)]
⎜ ↳ Virtual core XTEST pointer id=4 [slave pointer (2)]
⎜ ↳ FTCS1000:00 2808:0101 Touchpad id=10 [slave pointer (2)]
⎜ ↳ FTCS1000:00 2808:0101 Mouse id=11 [slave pointer (2)]
⎣ Virtual core keyboard id=3 [master keyboard (2)]
↳ Virtual core XTEST keyboard id=5 [slave keyboard (3)]
↳ Video Bus id=6 [slave keyboard (3)]
↳ Power Button id=7 [slave keyboard (3)]
↳ Sleep Button id=8 [slave keyboard (3)]
↳ USB2.0 HD UVC WebCam: USB2.0 HD
same here!
I was able to disable it with:
xinput –disable [id]
Thanks, works great :-)
Linux Mint 21.