3

I need to block all USB storage devices (pendrives & mobile devices) but I need to access USB keyboard and USB mouse.

I have already tried by editing /etc/modprobe.d/blacklist.conf by adding blacklist usb_storage but still the system can access USB devices.

2
  • What version of Ubuntu you have?
    – BDRSuite
    Feb 28, 2017 at 6:33
  • Ubuntu 13.10 and tried in Ubuntu 16.04LTS Feb 28, 2017 at 6:39

4 Answers 4

4

I found in Ubuntu 16.04, some pendrives trigger pickup of the uas.ko kernel driver (USB Attached SCSI driver). And a kernel driver dependency of uas.ko is usb_storage.ko.

Hence, eventhough I had blacklist usb_storage in /etc/modprobe.d/blacklist.conf, usb_storage.ko still got loaded by virtue of dependency to uas.ko

After placing in:

blacklist uas
blacklist usb_storage

into /etc/modprobe.d/blacklist.conf, access to those pendrives no longer works (uas.ko & usb_storage.ko no longer loads) in a running system.

Bear in mind to enforce this during kernel boot, one would also need to make some grub/kernel line modifications of some similar sort in link.

2

Another, To disable USB storage, create the following file and edit it with your favourite text editor.

/etc/modprobe.d/usb-storage.conf

Within this file, add the following line.

install usb-storage /bin/true

After saving that line to the /etc/modprobe.d/usb-storage.conf file you will need to perform a reboot to complete the process. After rebooting if you plug in a USB storage device you should not be able to access it.

2
  • This doesn't work for me on Ubuntu 18.04
    – BSUK
    Feb 11, 2019 at 15:56
  • This worked for me.
    – gerardw
    Jan 6, 2020 at 16:52
1

From cyberciti:

The usb-storage.ko is the USB Mass Storage driver for Linux operating system. You can see the file typing the following command:

ls -l /lib/modules/$(uname -r)/kernel/drivers/usb/storage/usb-storage.ko

All you have to do is disable or remove the usb-storage.ko driver to restrict to use USB devices on Linux such as:

  1. USB keyboards
  2. USB mice
  3. USB pen drive
  4. USB hard disk
  5. Other USB block storage

BIOS option

You can also disable USB from system BIOS configuration option. Make sure BIOS is password protected. This is recommended option so that nobody can boot it from USB.


Grub option

You can get rid of all USB devices by disabling kernel support for USB via GRUB. Open grub.conf or menu.lst and append "nousb" to the kernel line as follows (taken from RHEL 5.x):

kernel /vmlinuz-2.6.18-128.1.1.el5 ro root=LABEL=/ console=tty0 console=ttyS1,19200n8 nousb

Make sure you remove any other reference to usb-storage in the grub or grub2 config files. Save and close the file. Once done just reboot the system:

reboot

Hope this helps.

3
  • grub.conf or menu.lst? This looks like a GRUB 1 solution. Ubuntu uses GRUB 2 since 9.10 and it has different configuration files (both location and syntax).
    – Melebius
    Feb 28, 2017 at 6:57
  • 4
    but i need to access USB keyboard and USB mouse Feb 28, 2017 at 6:58
  • i asked all USB storage devices Feb 28, 2017 at 7:00
1

on /etc/modprobe.d/blacklist.conf add

blacklist uas
blacklist usb-storage

disable uas mod also , i don't kow why it's necessary to blacklist module of uas protocol but it worked for me

3
  • Welcome to Ask Ubuntu! Could you please explain why it's necessary or beneficial to disable the uas module in this case? (See also How do I write a good answer? for general advice about what sorts of answers are considered most valuable on Ask Ubuntu.) Jan 16, 2018 at 13:28
  • Hi,i'm not sure why it's necessary but it worked for me disabling uas module protocol since blacklisting usb-storage module only didn't work
    – jahly
    Jan 16, 2018 at 13:35
  • Could you please edit your post, when you want to clarify something or add information? It’s best to have everything relevant in one place. Additionally, comments may be deleted for various reasons. Thanks. Jan 16, 2018 at 13:36

Not the answer you're looking for? Browse other questions tagged .