0

Is there a command line (CLI) command to disable all keyboards on a machine, and then also a CLI command to re-enable them?

I'm on a laptop with an internal and external keyboard, I need to disable/enable both of them.

More Details

I'm on Ubuntu 22.04.3 LTS.

It should disable the keyboards across the board, it should not work anywhere at all (CLI, GUI, etc).

I'm creating a bash script that disables all keyboards for a finite time, once the time is up the script re-enables the keyboards.

4
  • 1
    How would you re-enable it from the command line if you have disabled the keyboards? Copy/paste? And what operating system are you using? If Linu, which one and which GUI? Is there a GUI? Is this only for non-GUI use? Please edit your question and give us some context. Commented Nov 29, 2023 at 15:54
  • So you want to disable the "harddrive", not just the tty? Nearly everibody uses keyboards, so it is built-in in the kernel, but you can (IIRC) build them as module, and so you can remove and install it again. Possibly you can do in the second layer (but I never see it as a problem, so not idea) Commented Nov 29, 2023 at 15:59
  • 1
    if X11 see xinput. If Wayland maybe this can help. Commented Nov 29, 2023 at 16:22
  • This is also highly relevant. Commented Nov 29, 2023 at 16:29

2 Answers 2

0

check out usbguard, it is available in Redhat/CentOS/Rocky as an rpm. Not sure about ubuntu.

If you can get it to install on your distribution, it will work at making anything connected via usb not work (ask me how i know) - if your rules file does not allow it. It is a systemd service so conceivably it could be as simple as service usbguard start to disable everything if the rules file says deny all and doesn't allow anything, and service usbguard stop to then allow the usb connected keyboards and whatnot.

I don't know if it would affect a laptop internal keyboard, if those are still done via usb connection then it should.

https://usbguard.github.io/

check out the source code to see how they accomplish it: https://github.com/USBGuard/usbguard/releases

0

How to disable the built-in keyboard on Rocky Linux (minimum CLI setup)?

Run the following command to disable the built-in (PS/2) keyboard permanently:

sudo grubby --args="i8042.nokbd" --update-kernel=ALL
sudo reboot

If you ever want to re-enable the keyboard, just run:

sudo grubby --remove-args="i8042.nokbd" --update-kernel=ALL
sudo reboot
1
  • As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center. Commented Apr 5 at 19:11

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.