Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I want to disable usb based on vendor id in linux environment. i want to allow only specific usb's only based on vendor id.

share|improve this question

This should be possible using udev rules, but is probably not easy and will require some experimentation. It is possible to accidentally do bad things like blocking your mouse and keyboard from working requiring restore with a live USB stick. I haven't tested these commands, caveat emptor.

Create a new file with a low priority number, eg /lib/udev/rules.d/20-block-usb.rules with contents:

BUS=="usb", PROGRAM="/bin/ %s{idVendor} %s{idProduct}", RESULT!="allow", OPTIONS+="ignore_device"

When a USB device is inserted, /bin/ should be called with the vendor and product IDs of the device as arguments, and unless it echoes allow then the device should be ignored, eg:


if [ "$vendor" = "0123" ]; then
    if [ "$product" = "4567" ]; then
        echo allow

You will probably want to look into udevtest for experimenting with rules, and as noted, you need to make sure your mouse, keyboard etc are whitelisted. You may want to restrict the blocking rule only to USB block devices by adding SUBSYSTEM=="block", before PROGRAM in the original rule.

share|improve this answer
thank you very much – subbarao Feb 11 '13 at 9:12
i have one doubt where we have to add a rule. is it in /etc/udev/rules.d/rule files or /lib/udev/rules.d/rule files. – subbarao Mar 4 '13 at 8:23
the rule is not working – subbarao Mar 5 '13 at 6:19

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.