Resetting a USB device from the command line in Linux can help resolve issues without rebooting the system.
Contents
1. Identify the USB Device
First, list connected USB devices to find the bus and device number:
lsusb
Example output:
Bus 002 Device 003: ID 0781:5581 SanDisk Corp. Ultra
Bus 001 Device 002: ID 8087:0024 Intel Corp. Integrated Rate Matching Hub
Note the Bus
(e.g., 002
) and Device
(e.g., 003
) numbers of the problematic device.
2. Reset Using usbreset
Utility
Install usbreset
(if missing)
Compile and install it from source:
sudo apt install build-essential git # Debian/Ubuntu
git clone https://github.com/gregkh/usbreset
cd usbreset
cc usbreset.c -o usbreset
sudo cp usbreset /usr/local/bin/
Reset the Device
Use the device’s vendor:product ID from lsusb
:
sudo usbreset 0781:5581 # Replace with your device's ID
Or use the bus and device number (from Step 1):
sudo usbreset /dev/bus/usb/002/003
3. Unbind and Rebind via Sysfs
Reset the USB device driver without unplugging:
# Find the USB device path (e.g., 2-1.4)
lsusb -t
# Unbind the device (replace X.Y with the port number)
echo 'X.Y' | sudo tee /sys/bus/usb/drivers/usb/unbind
# Rebind the device
echo 'X.Y' | sudo tee /sys/bus/usb/drivers/usb/bind
4. Power-Cycle the USB Port with uhubctl
For USB hubs, use uhubctl
to toggle power:
# Install uhubctl
sudo apt install uhubctl # Debian/Ubuntu
# List USB hubs
sudo uhubctl
# Power cycle port 4 on hub 2 (example)
sudo uhubctl -l 2 -p 4 -a cycle
5. Reset Entire USB Controller (Last Resort)
Reset all devices connected to a USB controller (e.g., usb1
):
# Disable the controller
echo 0 | sudo tee /sys/bus/usb/devices/usb1/authorized
# Re-enable it
echo 1 | sudo tee /sys/bus/usb/devices/usb1/authorized
Troubleshooting Tips
- Permissions: Use
sudo
for all commands. - Device Not Found: Physically unplug/replug the device if it doesn’t appear in
lsusb
. - Persistent Issues: Check
dmesg
for errors:
dmesg | grep -i usb
Summary Table
Method | Command Example | Use Case |
---|---|---|
usbreset | sudo usbreset 0781:5581 | Targeted device reset |
Sysfs bind/unbind | echo '2-1.4' > unbind/bind | Driver reinitialization |
uhubctl | sudo uhubctl -l 2 -p 4 -a cycle | Hub port power cycling |
Full controller reset | echo 0 > authorized; echo 1 > authorized | Drastic USB controller reset |