Hello,
How can I disable USB ports on Raspberry Pi 3 with Raspian OS ?
Re: Disable USB ports
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.
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.
Re: Disable USB ports
Note that disabling power to the ports is an all or nothing action. You can't disable individual ports.
Re: Disable USB 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.rpdom wrote:Note that disabling power to the ports is an all or nothing action. You can't disable individual ports.
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.
- mahjongg
- Forum Moderator
- Posts: 15100
- Joined: Sun Mar 11, 2012 12:19 am
- Location: South Holland, The Netherlands
Re: Disable USB ports
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.
You can measure the resistance between the VCC lines of the USB ports, its zero, meaning all power lines are wired together.
Re: Disable USB ports
This is not how I remember it, but will check in a few days and report back.
Re: Disable USB ports
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
Re: Disable USB ports
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).
Re: Disable USB ports
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:
root@rs:~# sudo uhubctl -a 0 -p 2
Follows by error message:
sudo: uhubctl: command not found
Can you help me please?
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:
root@rs:~# sudo uhubctl -a 0 -p 2
Follows by error message:
sudo: uhubctl: command not found
Can you help me please?
Re: Disable USB ports
RobW77 -
Did you follow the installation instructions at https://github.com/mvp/uhubctl ?
Did you follow the installation instructions at https://github.com/mvp/uhubctl ?
Re: Disable USB ports
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.
Quis custodiet ipsos custodes?
-
- Posts: 1
- Joined: Fri Jun 29, 2018 12:00 am
Re: Disable USB ports
This worked perfectly!smoneck wrote: ↑Mon Oct 02, 2017 11:57 amWorks 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
Re: Disable USB ports
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
Re: Disable USB ports
AIUI that statement is still true. Note that turning off power to a USB port is NOT the same thing as disabling it.kolsi wrote: ↑Fri May 17, 2019 8:59 amA bit older topic, but just a question. Is the statement above true for RPi3B+ ?
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.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
Quis custodiet ipsos custodes?
Re: Disable USB ports
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.