Skip to content

Instantly share code, notes, and snippets.

@evaporei
Created February 26, 2019 16:50
Show Gist options
  • Save evaporei/58a0b9f60763a5222b4bfe763014ddca to your computer and use it in GitHub Desktop.
Save evaporei/58a0b9f60763a5222b4bfe763014ddca to your computer and use it in GitHub Desktop.
Script to make USB device work on Linux
device_info_output="$(lsusb | grep $1)"
device_info_array=($device_info_output)
bus_number="${device_info_array[1]}"
device_number="${device_info_array[3]::-1}"
echo "${bus_number}"
echo "${device_number}"
sudo chmod 777 /dev/bus/usb/"$bus_number"/"$device_number"
@evaporei
Copy link
Author

How to use

First run this in your terminal:

lsusb

This will list all USB devices connected to your computer. The output will have a format similar to this:

Bus 002 Device 002: ID 0bda:0316 Realtek Semiconductor Corp.
Bus 002 Device 001: ID 1d6b:0003 Linux Foundation 3.0 root hub
Bus 001 Device 004: ID 138a:0097 Validity Sensors, Inc.
Bus 001 Device 003: ID 13d3:5619 IMC Networks
Bus 001 Device 002: ID 8087:0a2b Intel Corp.
Bus 001 Device 009: ID 1753:c902 GERTEC Telecomunicacoes Ltda.
Bus 001 Device 008: ID 045e:070f Microsoft Corp. LifeChat LX-3000 Headset
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub

Then run the script of this gist passing the name of the device as an argument, like this:

sh enable_usb_device.sh GERTEC

Now your USB device will be enabled to use 🙂

@evaporei
Copy link
Author

Another way to solve the problem that doesn't require to run this script everytime is to create a file like this:

Name: /usr/lib/udev/rules.d/50-name_of_your_device.rules
Content:

SUBSYSTEM=="usb", ATTR{idVendor}=="vendor_id_of_website", MODE="0777", GROUP="plugdev"

Where:

  • name_of_your_device can be what ever you want, in my opinion it is better to reference something that references your device (ex: gertec);
  • vendor_id_of_website should be a number that is on this website: http://www.linux-usb.org/usb.ids. To find your USB id just use Ctrl + F and look for your device name.

Example, my device is from Gertec:

screenshot-gertec-id-device

So the content of my file should be:

SUBSYSTEM=="usb", ATTR{idVendor}=="1753", MODE="0777", GROUP="plugdev"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment