CyrilRoy
Posts: 1
Joined: Sun Jan 22, 2017 11:29 am

Disable USB ports

Sun Jan 22, 2017 11:31 am

Hello,

How can I disable USB ports on Raspberry Pi 3 with Raspian OS ?

jpers
Posts: 24
Joined: Mon May 23, 2016 6:06 am

Re: Disable USB ports

Sun Jan 22, 2017 6:10 pm

I know two ways to do this, but I am afraid both of them are incomplete solutions, and perhaps a complete one is not possible, since other peripherals use USB bus (for example, Ethernet).

First solution: Cut the power to the ports you do not need. This will effectively disable the use of USB-powered peripherals (that is almost all of them), unless a (malicious?) user will power the peripherals externally.
Fortunately, this solution is possible entirely in userland - there is utility called hub-ctrl for that, and it works on Raspberry Pi.

viewtopic.php?p=813383#p813383

Second solution: Reconfigure the kernel and remove drivers for all devices you want to prevent to communicate via USB ports. I successfully compiled kernel version that did not support HID devices (keyboard/mouse) so USB mouse or keyboard did not work.

Third solution, which would be a complete solution, is to remove USB support from the kernel, but this may break many other things, Ethernet first. Try and report.

User avatar
rpdom
Posts: 14111
Joined: Sun May 06, 2012 5:17 am
Location: Chelmsford, Essex, UK

Re: Disable USB ports

Sun Jan 22, 2017 6:19 pm

Note that disabling power to the ports is an all or nothing action. You can't disable individual ports.

jpers
Posts: 24
Joined: Mon May 23, 2016 6:06 am

Re: Disable USB ports

Sun Jan 22, 2017 6:53 pm

rpdom wrote:Note that disabling power to the ports is an all or nothing action. You can't disable individual ports.
You can, according to the link I posted (I tested the method, it works, but did not observed all the ports, since only one peripheral was attached in my setup). Unless things changed since the post I link to.

One of the ports (number 1, i think) cannot be controlled individually, the other three could be. I suspect number 1 is connected to Ethernet, so it is impractical as well.

User avatar
mahjongg
Forum Moderator
Forum Moderator
Posts: 11737
Joined: Sun Mar 11, 2012 12:19 am
Location: South Holland, The Netherlands

Re: Disable USB ports

Sun Jan 22, 2017 6:59 pm

there is no hardware to disable individual ports. Some models of PI do not even have any means of disabling power to any USB port.

You can measure the resistance between the VCC lines of the USB ports, its zero, meaning all power lines are wired together.

jpers
Posts: 24
Joined: Mon May 23, 2016 6:06 am

Re: Disable USB ports

Mon Jan 23, 2017 7:20 pm

This is not how I remember it, but will check in a few days and report back.

smoneck
Posts: 5
Joined: Mon Oct 02, 2017 11:53 am

Re: Disable USB ports

Mon Oct 02, 2017 11:57 am

Works for me on RPi 3b:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=162539#p1051587 wrote:To shut off power on USB ports (this shuts power on ethernet as well):
echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/unbind

To turn power back on
echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/bind

smoneck
Posts: 5
Joined: Mon Oct 02, 2017 11:53 am

Re: Disable USB ports

Tue Oct 03, 2017 6:44 am

I just found: On at least RPi3b power of all [USB-ports] and [Ethernet+WiFi] can be switched separately. There is a tool called uhubctl doing this using libusb (port 1 for Ethernet+Wifi, port 2 for USB).

RobW77
Posts: 2
Joined: Sun Dec 17, 2017 1:39 pm

Re: Disable USB ports

Sun Dec 17, 2017 1:46 pm

Hi smoneck,
I tried it with uhubctl but it doesn't work.

I installed the package:
sudo apt-get install libusb-1.0-0-dev

Then the command:
[email protected]:~# sudo uhubctl -a 0 -p 2

Follows by error message:
sudo: uhubctl: command not found

Can you help me please?

robbes
Posts: 144
Joined: Sun Jan 20, 2013 7:11 pm
Location: Canada - off the west coast

Re: Disable USB ports

Mon Dec 18, 2017 7:19 pm

RobW77 -
Did you follow the installation instructions at https://github.com/mvp/uhubctl ?

drgeoff
Posts: 9251
Joined: Wed Jan 25, 2012 6:39 pm

Re: Disable USB ports

Wed Dec 20, 2017 5:52 pm

You CANNOT control the power to individual USB ports on a RPi. The power pins are commoned by PCB tracking. No software can change that.

spicygal808
Posts: 1
Joined: Fri Jun 29, 2018 12:00 am

Re: Disable USB ports

Fri Jun 29, 2018 12:04 am

smoneck wrote:
Mon Oct 02, 2017 11:57 am
Works for me on RPi 3b:
https://www.raspberrypi.org/forums/viewtopic.php?f=29&t=162539#p1051587 wrote:To shut off power on USB ports (this shuts power on ethernet as well):
echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/unbind

To turn power back on
echo '1-1' | sudo tee /sys/bus/usb/drivers/usb/bind
This worked perfectly!

kolsi
Posts: 11
Joined: Wed Jan 23, 2019 10:40 am

Re: Disable USB ports

Fri May 17, 2019 8:59 am

drgeoff wrote:
Wed Dec 20, 2017 5:52 pm
You CANNOT control the power to individual USB ports on a RPi. The power pins are commoned by PCB tracking. No software can change that.
A bit older topic, but just a question. Is the statement above true for RPi3B+ ?

Code: Select all

~$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/3p, 480M
            |__ Port 1: Dev 6, If 0, Class=Vendor Specific Class, Driver=lan78xx, 480M
        |__ Port 2: Dev 7, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        |__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 3: Dev 4, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
If I execute echo '1-1.2' | sudo tee /sys/bus/usb/drivers/usb/unbind (where numbers are BUS-PORT.SUBPORT) it disables the port with USB storage only, Ethernet and other ports still work.

drgeoff
Posts: 9251
Joined: Wed Jan 25, 2012 6:39 pm

Re: Disable USB ports

Fri May 17, 2019 11:13 am

kolsi wrote:
Fri May 17, 2019 8:59 am
drgeoff wrote:
Wed Dec 20, 2017 5:52 pm
You CANNOT control the power to individual USB ports on a RPi. The power pins are commoned by PCB tracking. No software can change that.
A bit older topic, but just a question. Is the statement above true for RPi3B+ ?

Code: Select all

~$ lsusb -t
/:  Bus 01.Port 1: Dev 1, Class=root_hub, Driver=dwc_otg/1p, 480M
    |__ Port 1: Dev 2, If 0, Class=Hub, Driver=hub/4p, 480M
        |__ Port 1: Dev 3, If 0, Class=Hub, Driver=hub/3p, 480M
            |__ Port 1: Dev 6, If 0, Class=Vendor Specific Class, Driver=lan78xx, 480M
        |__ Port 2: Dev 7, If 0, Class=Mass Storage, Driver=usb-storage, 480M
        |__ Port 3: Dev 4, If 0, Class=Human Interface Device, Driver=usbhid, 1.5M
        |__ Port 3: Dev 4, If 1, Class=Human Interface Device, Driver=usbhid, 1.5M
If I execute echo '1-1.2' | sudo tee /sys/bus/usb/drivers/usb/unbind (where numbers are BUS-PORT.SUBPORT) it disables the port with USB storage only, Ethernet and other ports still work.
AIUI that statement is still true. Note that turning off power to a USB port is NOT the same thing as disabling it.

kolsi
Posts: 11
Joined: Wed Jan 23, 2019 10:40 am

Re: Disable USB ports

Wed May 29, 2019 11:04 am

Yes, you are right. I did some experiments and it is possible to disable individual ports '1-1.x.y' but they are still powered in the disabled state (e.g. USB flash disk is off, its LED is off but I can still charge my phone in the disabled port). Only completely disabling '1-1' turns the power off.

Return to “Advanced users”