Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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

1 Answer 1

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/filter_usb.sh %s{idVendor} %s{idProduct}", RESULT!="allow", OPTIONS+="ignore_device"

When a USB device is inserted, /bin/filter_usb.sh 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:

#!/bin/sh
vendor=$1
product=$2

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

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

 
discard

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.