Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

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

Is it possible to reset the connection of a USB device, without physically disconnecting/connecting from the PC?

Specifically, my device is a digital camera. I'm using gphoto2, but lately I get "device read errors", so I'd like to try to do a software-reset of the connection.

From what I can tell, there are no kernel modules being loaded for the camera. The only one that looks related is usbhid.

share|improve this question
Which version of Ubuntu are you using? – User Aug 1 '10 at 20:15
i tried both solutions by Li Lo and ssokolow, all i get is permission denied, nomatter if i use the usbreset code or the command line "echo 0 > ..." i use sudo, also my usb devices are owned by root but i can use them without admin rights(cameras..) – user290672 Jun 8 '14 at 16:40
If you are getting read errors, you might have some data corruption. If your camera uses an external memory card (such as MicroSD), it might be wise to connect it to the computer and run fsck. – TSJNachos117 Jun 8 '14 at 18:47

10 Answers 10

up vote 63 down vote accepted

Save the following as usbreset.c

/* usbreset -- send a USB port reset to a USB device */

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <errno.h>
#include <sys/ioctl.h>

#include <linux/usbdevice_fs.h>

int main(int argc, char **argv)
    const char *filename;
    int fd;
    int rc;

    if (argc != 2) {
        fprintf(stderr, "Usage: usbreset device-filename\n");
        return 1;
    filename = argv[1];

    fd = open(filename, O_WRONLY);
    if (fd < 0) {
        perror("Error opening output file");
        return 1;

    printf("Resetting USB device %s\n", filename);
    rc = ioctl(fd, USBDEVFS_RESET, 0);
    if (rc < 0) {
        perror("Error in ioctl");
        return 1;
    printf("Reset successful\n");

    return 0;

The run the following commands in terminal:

  1. Compile the program:

    $ cc usbreset.c -o usbreset
  2. Get the Bus and Device ID of the USB device you want to reset:

    $ lsusb  
    Bus 002 Device 003: ID 0fe9:9010 DVICO  
  3. Make our compiled program executable:

    $ chmod +x usbreset
  4. Execute the program with sudo privilege; make necessary substitution for <Bus> and <Device> ids as found by running the lsusb command:

    $ sudo ./usbreset /dev/bus/usb/002/003  

Source of above program:

share|improve this answer
I got errors like this: ./usbreset: command not found Dan 11.04 Natty – user24895 Sep 13 '11 at 4:33
Thank you so much! This will help me get a lot more life out of my dying Intellimouse. – Randall Ma Dec 15 '13 at 0:55
This works with ubuntu 13.10. The device ID can vary. TO get it for the mouse I have wrapped above code in few shell commands echo $(lsusb | grep Mouse) mouse=$( lsusb | grep Mouse | perl -nE "/\D+(\d+)\D+(\d+).+/; print qq(\$1/\$2)") sudo /path/to/c-program/usbreset /dev/bus/usb/$mouse – knb Dec 22 '13 at 11:04
my external drive seems to become undetectable (I have to hard reconnect the usb cable); it is a usb2.0 connected on a usb3.0 desktop PC port; when I run usbreset /dev/bus/usb/011/001 that is one of the 2 usb 3.0 root hubs at lsusb, it errors: "Error in ioctl: Is a directory", any ideia? I tried on both usb 3.0 hubs – Aquarius Power Oct 30 '14 at 3:34
If anyone reading this have a (usb) mouse freeze after logging in on Ubuntu 16.04 (with dmesg filled by "input irq status -75") , i can confirm that this is the only solution that worked for me. Thank you – agustinrc89 May 2 at 12:31

I haven't found myself in your specific circumstances before, so I'm not sure if it'll do enough, but the simplest way I've found to reset a USB device is this command: (No external apps necessary)

sudo sh -c "echo 0 > /sys/bus/usb/devices/1-4.6/authorized"
sudo sh -c "echo 1 > /sys/bus/usb/devices/1-4.6/authorized"

That's the actual one I use to reset my Kinect since libfreenect seems to have no API for putting it back to sleep. It's on my Gentoo box, but the kernel should be new enough to use the same path structure for sysfs.

Yours obviously wouldn't be 1-4.6 but you can either pull that device path from your kernel log (dmesg) or you can use something like lsusb to get the vendor and product IDs and then use a quick command like this to list how the paths relate to different vendor/product ID pairs:

for X in /sys/bus/usb/devices/*; do 
    echo "$X"
    cat "$X/idVendor" 2>/dev/null 
    cat "$X/idProduct" 2>/dev/null
share|improve this answer
sh: 1: cannot create /sys/bus/usb/devices/1-3.1:1.0/authorized: Directory nonexistent – Nicolas Marchildon May 31 '12 at 3:22
It looks like they've changed the layout of the usbfs filesystem. I'll try to figure out what the new way of doing things is on Ubuntu once I'm not so sleepy. – ssokolow Jun 2 '12 at 15:46
Thank you worked great! Maybe you should also mention to perform a echo 1 > /sys/bus/usb/devices/whatever/authorized inside a script to re-enable the device as soon as it has been disabled. I did it on both my mouse and usb keyboard and I ended up with a completely deaf system :) – Avio Apr 28 '13 at 8:43
Last time I used it, something in the system would reset it to 1 a second or two later without me having to do it manually. – ssokolow Apr 29 '13 at 20:33
It's extremely strange if it automatically re-set the value to 1 as setting it to 0 is telling the system you don't want the device to be "authorized" and therefore inaccessible. – Tim Tisdall Oct 18 '13 at 19:45

This will reset all of USB2/3 attached ports[1]:

# reseting USB2 ports
for i in $(ls /sys/bus/pci/drivers/ehci_hcd/|grep :)
 do echo $i >/sys/bus/pci/drivers/ehci_hcd/unbind
 echo $i >/sys/bus/pci/drivers/ehci_hcd/bind
# reseting USB3 ports (if there none you'll get errors)
for i in $(ls /sys/bus/pci/drivers/xhci_hcd/|grep :)
 do echo $i >/sys/bus/pci/drivers/xhci_hcd/unbind
 echo $i >/sys/bus/pci/drivers/xhci_hcd/bind

I believe this will solve your problem. If you do not want to reset all of the USB endpoints, you can use appropriate device ID from /sys/bus/pci/drivers/ehci_hcd

Notes: [1]: the ehci_hcd and xhci_hcd kernel drivers typically control the USB ports. ehci_hcd is for USB2 ports and xhci_hcd is for USB3 ports.

P.S. It solved my (ndemou) problems on a Dell XPS13 notebook were the USB controller (especially the USB3 one) was locking up every few days or weeks. In case it helps someone else lspci on my ubuntu 12.04 reports these USB controllers:

  • Fresco Logic FL1009 USB 3.0 Host Controller (rev 02)
  • Intel Corporation 6 Series/C200 Series Chipset Family USB Enhanced Host Controller #1 (rev 05)

(Sorry for the PS but I don't have enough reputation to add a comment -- still I think it might help someone else googling for the same notebook/controllers)

share|improve this answer
do you believe it may work to wakeup an usb storage? – Aquarius Power Jun 30 '14 at 5:53
Although I've received the following message: ls: cannot access /sys/bus/pci/drivers/ehci_hcd/: No such file or directory this has resolved the issue, the mouse has started working immediately. +1 – Attila Fulop Oct 10 '14 at 6:16
is it possible to add a check to skip mounted USB mass storage devices? – eadmaster Nov 1 '15 at 10:32
uhci_hcd on rhel7 QEMU environment – Otheus Apr 19 at 10:19
@Otheus OHCI and UHCI are the USB 1.1 host standards, EHCI is the USB 2.0 host standard, and XHCI is the USB 3.0 host standard. – ssokolow Jul 20 at 19:02

Quickest way to reset will be to reset the USB controller itself. Doing so will enforce udev to unregister the device on disconnection, and register is back once you enable it.

echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci_hcd/unbind
echo -n "0000:00:1a.0" | tee /sys/bus/pci/drivers/ehci_hcd/bind
echo -n "0000:00:1d.0" | tee /sys/bus/pci/drivers/ehci_hcd/bind

This should work for most PC environment. However, if you are using some custom hardware you can simply iterate through the device names. With this method you don't need to find out the device name by lsusb. You can incorporate in a automated script as well.

share|improve this answer
You need to run these commands as root/sudo, and it will not work on all systems (on some, you'll need to replace ehci_hcd with ehci-pci. More info on this solution (perhaps where it came from?):… – Lambart Nov 5 '15 at 17:43

I needed to automate this in a python script, so I adapted LiLo's extremely helpful answer to the following:

#!/usr/bin/env python
import os
import sys
from subprocess import Popen, PIPE
import fcntl
driver = sys.argv[-1]
print "resetting driver:", driver

    lsusb_out = Popen("lsusb | grep -i %s"%driver, shell=True, bufsize=64, stdin=PIPE, stdout=PIPE, close_fds=True)
    bus = lsusb_out[1]
    device = lsusb_out[3][:-1]
    f = open("/dev/bus/usb/%s/%s"%(bus, device), 'w', os.O_WRONLY)
    fcntl.ioctl(f, USBDEVFS_RESET, 0)
except Exception, msg:
    print "failed to reset device:", msg

In my case it was the cp210x driver (which I could tell from lsmod | grep usbserial), so you could save the above snippet as and then do this:

sudo python cp210x

This might also be helpful if you don't already have a c compiler setup on your system, but you do have python.

share|improve this answer
worked for me on a Raspberry – webo80 Jun 23 at 14:36

I'm using kind of sledgehammer by reloading the modules. This is my script:


# USB drivers
rmmod xhci_pci
rmmod ehci_pci

# uncomment if you have firewire
#rmmod ohci_pci

modprobe xhci_pci
modprobe ehci_pci

# uncomment if you have firewire
#modprobe ohci_pci

And this is my systemd service file /usr/lib/systemd/system/usbreset.service which runs after my diplay manager has started:

Description=usbreset Service

share|improve this answer

Perhaps this works for a camera, too:

Following revived a starved USB 3.0 HDD on a 3.4.42 ( Linux on my side. dmesg told, that it was timing out commands after 360s (sorry, I cannot copy the syslog here, not connected networks) and the drive hung completely. Processes accessing the device were blocked in the kernel, unkillable. NFS hung, ZFS hung, dd hung.

After doing this, everything worked again. dmesg told just a single line about the USB device found.

I really have no idea what following does in detail. But it worked.

The following example output is from Debian Squeeze with 2.6.32-5-686 kernel, so I think it works for 2.6 and above:

$ ls -al /dev/sdb
brw-rw---T 1 root floppy 8, 16 Jun  3 20:24 /dev/sdb

$ ls -al /sys/dev/block/8:16/device/rescan
--w------- 1 root root 4096 Jun  6 01:46 /sys/dev/block/8:16/device/rescan

$ echo 1 > /sys/dev/block/8:16/device/rescan

If this does not work, perhaps somebody else can figure out how to send a real reset to a device.

share|improve this answer

Try this, it's a software unplug (Eject).

Sometimes doesn't work simply unbind device for some devices.


I want to remove or eject my "Genius NetScroll 120".

Then i first Check my attached usb device

$ lsusb
Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 002 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root hub
Bus 001 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 002 Device 002: ID 8087:0020 Intel Corp. Integrated Rate Matching Hub
Bus 001 Device 003: ID 03f0:231d Hewlett-Packard 
Bus 001 Device 004: ID 138a:0007 Validity Sensors, Inc. VFS451 Fingerprint Reader
Bus 001 Device 005: ID 04f2:b163 Chicony Electronics Co., Ltd 
Bus 002 Device 009: ID 0458:003a KYE Systems Corp. (Mouse Systems) NetScroll+ Mini Traveler / Genius NetScroll 120  **<----This my Mouse! XDDD**

Ok, i found my mouse, it's has a Bus 002, Device 009, idVendor 0458 and idProduct 003a, so this is a reference device info about the mouse.

This is important, the Bus number is the begin name path to device and i will check the product Id and Vendor to ensure the correct device to remove.

$ ls /sys/bus/usb/drivers/usb/
1-1/    1-1.1/  1-1.3/  1-1.5/  2-1/    2-1.3/  bind    uevent  unbind  usb1/   usb2/

Pay atention on the folders, check the begining with folder number 2, i will check this one because my Bus is 002, and one by one i have check each folder containing the correct idVendor and idProduct about my mouse info.

In this case, i will retrieve the info with this command:

cat /sys/bus/usb/drivers/usb/2-1.3/idVendor
cat /sys/bus/usb/drivers/usb/2-1.3/idProduct

Ok, the path /sys/bus/usb/drivers/usb/2-1.3/ match with my info mouse! XDDD.

It's time to remove the device!

su -c "echo 1 > /sys/bus/usb/drivers/usb/2-1.3/remove"

Plug again the usb device and it's work again!

share|improve this answer
What if you can't plug it in again? (for example it's an internal sdcard reader) – aleb Jun 29 '14 at 20:57

Did somebody order a sledgehammer? This is pieced together from various other answers here.


# Root required
if (( UID )); then
        exec sudo "$0" "$@"

cd /sys/bus/pci/drivers

function reinit {(
        local d="$1"
        test -e "$d" || return

        rmmod "$d"

        cd "$d"

        for i in $(ls | grep :); do
                echo "$i" > unbind

        sleep 1

        for i in $(ls | grep :); do
                echo "$i" > bind

        modprobe "$d"


for d in ?hci_???; do
        echo " - $d"
        reinit "$d"
share|improve this answer

Maybe this guide can help you:

If you are pestered by the bug that doesn;t let you mount USB devices in Ubuntu Lucid Lynx, the issue is caused by the floppy module. Disable it with:

sudo modprobe -r floppy

After a reboot the module will likely reload.

share|improve this answer

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.