Performancing Metrics

Pages Menu
TwitterRssFacebook
Categories Menu

How to Disable and Enable USB Device in Linux

Updated by on Oct 21, 2012 in Linux | 10 comments

Here is the interesting tweak about how to disable usb storage device in linux, and only root / sudo users can alone enable / mount it from the terminal. Using the below tweak / method one can block normal / guest user from mounting the usb storage device.

Follow the steps

1) Add this line “blacklist usb_storage” to the end of /etc/modprobe.d/blacklist.conf

To add : Open a Terminal by using Ctrl+Alt+T or Applications->Accessories->Terminal. You need to have root access to do this tweak. Copy and paste the following command in the Terminal. Type the password for the user, when prompted.

sudo gedit /etc/modprobe.d/blacklist.conf

The above command will open the blacklist.conf file in gedit. You can use any editor to edit this file like vim, gvim, emacs etc., Now copy and paste this line “blacklist usb_storage” at the end of the file. After adding this save it and close the gedit. Check the below screen shot.

2) Add this line “modprobe -r usb_storage” before exit 0 in /etc/rc.local

To add : Copy and paste the following command in the Terminal. Type the password for the user, if prompted.

 sudo gedit /etc/rc.local

The above command will open the rc.local file in gedit. Now copy and paste this line “modprobe -r usb_storage” before the last line of the file. After adding this save it and close the gedit. Check the below screen shot for Fedora and Ubuntu.

For Ubunntu:

For Fedora:

Now restart your system.

To Mount USB device

Open a Terminal and use the following command. Type the password for the user, when prompted.

sudo modprobe usb_storage

To Unmount the USB device

Use “safely remove drive” by right click on the device, then run the below command in the Terminal. Type the password for the user, when prompted.

sudo rmmod usb_storage

Hope this will be helpful for you!!

Related Posts Plugin for WordPress, Blogger...
  • pvin

    On Ubuntu 11.04 with lk 3.0.0 this technique does not work. The usb_storage module continues to load.

    • http://www.howopensource.com Manivannan

      Hi dude, Today I checked on Ubuntu 11.04 with Linux Kernel 3.0.0 using VirtualBox and it works fine for me. I have updated the post with screen shots check it. Please write to me if it does not work.

      • http://www.howopensource.com/2011/08/how-to-disable-and-enable-usb-device-in-linux/ chaitanya

        it’s working dude very nice and thank u

  • revathy

    Interesting info… Expecting more such posts!!!!

    • http://www.howopensource.com Manivannan

      Thanks Revathy :)

  • http://www.sathia27.wordpress.com sathia

    great info.

    • http://www.howopensource.com Manivannan

      Thanks Sathia :)

  • http://www.linuxkernel51.blogspot.com GVK51

    The other way i do is, bind or unbind the specific port.

    For example if you have connected a mass storage device : go to the path below

    $ cd /sys/bus/usb/drivers/usb-storage/

    $ ls
    1-6:1.0 bind module new_id remove_id uevent unbind

    here 1-6:1.0 which is a unique id for the device connected this ID is based on the rules set in naming conventions for usb devices.

    now to disable : (mass storage)

    $ echo 1-6:1.0 > unbind

    to enable :

    $ echo 1-6:1.0 > bind

    ( assuming that you are in /sys/bus/usb/drivers/usb-storage)

    Similarly you can do for the any of usb devices based on their classe, like usbhid, usb-serial…. etc,

  • Pingback: usb disable

  • Suresh

    Hello Dear
    Thanks for your valuable info I am debut Fedora Userwith zero knowledge i have started and now i know very little..I want to install Dosbox 0.74 from its site to play good old DOS games like ‘Dave,’Prince, etc need your help please

  • dnyaneshwar

    hi
    its not working on fedora 14

  • Pingback: How to Disable Amazon search results in Ubuntu 12.10 Dash

  • Pingback: usb access restriction