Linux.com

Home Linux Community Community Blogs General Linux Disable & Enable USB from terminal

Disable & Enable USB from terminal

Hello guys, i'm the new user in this community. Hope all of you guys take me as the familly in this community.

2013-07-05-232714 1024x600 scrotIn this article, i would share about "how to disable usb from the terminal". This article i take from my blog, but, I write the article in Bahasa. So, I just convert it into english. The concept is very easy. In this case, I use several command from linux to operate the usb on/off with the bash shell scripting. And you must use the root for the access user. I have tried in linux ubuntu and work normally.

 

Before we going into the topic, I would to say something about my purpose creating this article. So, i have modem and my modem can connect with linux by using wvdial service. Wvdial is package on debian variety, used to dial your modem by terminal with carrier.  So, i have problem after I dial with this modem. That is, whenever i didn't got signal and the modem automatically disconnect. And whenever I tried to connect again with wvdial without I pull out my modem, the wvdial will be error and I can't connect again. So, to fix the problem, I thinking something. Yes, and that is "How I can control the usb off and on by terminal?".  Here we go, this is way how to do it :

  1. First time, our modem must be plugged into our usb. 
  2. After that, we trying to connect with wvdial command. Ups, I cannot got carrier.The first solution for a long time is I pull out the modem from usb and wait a few second than I plug again into usb. it's very make me feel bored and angry.
  3. So, to fix the problem without do the really bad clue. First time, You must open the terminal and make access as super user : "sudo lsusb -t|less", this command will be give you list the active usb. And in the result is :
  4. """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" 
         /:  Bus 05.Port 1: Dev 1, class="root_hub", Driver=uhci_hcd/2p, 12M
         /:  Bus 04.Port 1: Dev 1, class="root_hub", Driver=uhci_hcd/2p, 12M
         /:  Bus 03.Port 1: Dev 1, class="root_hub", Driver=uhci_hcd/2p, 12M
        |__ Port 1: Dev 2, If 0, class="HID", Driver=usbhid, 1.5M
        /:  Bus 02.Port 1: Dev 1, class="root_hub", Driver=uhci_hcd/2p, 12M
        |__ Port 1: Dev 6, If 0, class="vend"., Driver=usbserial_generic, 12M
        |__ Port 1: Dev 6, If 1, class="vend"., Driver=usbserial_generic, 12M
        |__ Port 1: Dev 6, If 2, class="vend"., Driver=usbserial_generic, 12M
        |__ Port 1: Dev 6, If 3, class="stor"., Driver=usb-storage, 12M
    |__ Port 2: Dev 3, If 0, class="HID", Driver=usbhid, 1.5M
        |__ Port 2: Dev 3, If 1, class="HID", Driver=usbhid, 1.5M
        /:  Bus 01.Port 1: Dev 1, class="root_hub", Driver=ehci_hcd/8p, 480M
        |__ Port 6: Dev 5, If 0, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M     |__ Port 6: Dev 5, If 1, Class='bInterfaceClass 0x0e not yet handled', Driver=uvcvideo, 480M
    """"""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""
  5. After we know the actived usb that connect with our modem. Do this command
       "echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/unbind" <- to make usb disable/turn off
    NB : '2-1' is the process that we will be kill.
    after you do that command, the usb will be disable.
  6. Trying to dial again with wvdial. So we have the result  :
    eject: unable to find or open device for: `/dev/sr0'
    --> WvDial: Internet dialer version 1.60
    --> Cannot open /dev/ttyUSB0: No such file or directory
    --> Cannot open /dev/ttyUSB0: No such file or directory
    --> Cannot open /dev/ttyUSB0: No such file or directory
    *This is good information.That's have mean, the usb succesfully set as disable.
  7. We do again the command such as step number 5 but with different input at the end. So ,like this :
    echo '2-1' |sudo tee /sys/bus/usb/drivers/usb/bind <- to make usb active again // the different command just in the end of syntax.
    NB : '2-1' is process that will be make enable.
  8. Try again with the wvdial command like as before. And.... i no need to pull out and plug in again modem in usb. So, the mainly command is in step 5 and 7.

    Thanks

    e-mail : This e-mail address is being protected from spambots. You need JavaScript enabled to view it
 

Comments

Subscribe to Comments Feed
  • shohanali Said:

    Australian Swingers Contacts Australian Swingers Contacts is the number 1 swinging resource for Australian Swingers in Australia! Here you can meet, chat, find friends and like minded couples or singles for partner/wife swapping fun. We have been growing fast in the Cities, why not have a look at some of the latest members in these cities Sydney, Melbourne, Brisbane, Perth, Townsville, Cairns, Adelaide, Gold Coast, Newcastle, Wollongong, Sunshine Coast, Hobart Geelong. Join Now Here:>> http://australianswingerscontacts.com/

  • n.subramaniam Said:

    Thanks a lot, it was superb as i am new to linux, and it is working really fine (enabling and disabling the usb)

  • Mikko Pakarinen Said:

    Thanks, good work! Usefull tip in a embedded linux system for saving power and reseting kinky usb-devices :)

  • ManojNamdev Said:

    can we bind any device with system, that only be accessible in system. apart from my pen drive others devices or even pen drive should not accessible in this system. Is it possible? only one particular USB devices should be accessible no one else.


Who we are ?

The Linux Foundation is a non-profit consortium dedicated to the growth of Linux.

More About the foundation...

Frequent Questions

Join / Linux Training / Board