I would like to disable any keyboard and mouse user puts in USB port (regardless their ID, vendor, name, ...). I found this article http://wpkg.org/Disable_/_enable_keyboard_and_mouse_in_Linux but it is not exactly what I am looking for. Any idea how to disable usb devices (keyboard, mouse, wireless keyboard/mouse) and leave usb port enabled just for usb mass storage?
Create a file called, e.g.,
/etc/modprobe.d/ and add the following line:
Then re-generate your initramfs with:
update-initramfs -u -k $(uname -r)
or, if you want to rebuild the initramfs for all installed kernel versions:
update-initramfs -u -k all
After you reboot,
usbhid.ko will be prevented from loading. This will persist for any new kernel versions you install until you either delete the
/etc/modprobe.d/usbhid.conf file or comment out the
blacklist line it contains (of course, you have to re-generate the initramfs again).
BTW if you need to attach a USB kbd/mouse to work on the console for any reason, you can
ssh in and run (as root):
insmod /lib/modules/$(uname -r)/kernel/drivers/hid/usbhid/usbhid.ko
and plug the keyboard/mouse into a usb socket. Unlike
insmod command ignores any entries (incl.
blacklist and module options) in
Don't forget to
rmmod usbhid when you don't need to use the kbd/mouse any more.