2 min read

Uhubctl lets you cut USB power port by port

uhubctl controls per-port USB power on supported smart hubs across Linux, macOS, and other Unix-like systems.

Image: Hacker News

uhubctl is a command-line utility for controlling USB power on individual ports of compatible smart hubs — hardware that supports per-port power switching rather than toggling all ports at once.

The project, hosted on GitHub by mvp, was originally inspired by Niibe Yutaka’s hub-ctrl.c. Its main limitation is hardware support: the repository maintains a long list of compatible devices, but notes that not many USB hubs correctly support per-port power switching, and some supported models are already discontinued. The list spans standalone hubs, monitors with internal hubs, docks, keyboards, motherboards, and systems including the Apple Mac Mini M4, Raspberry Pi 5, and several Dell, Lenovo, LG, AmazonBasics, Anker, and Plugable products.

On USB 3.0 hardware, the tool warns that a hub may appear as two virtual hubs — one for USB2 and one for USB3. In those cases, both sides often need to be switched for a full power change to take effect, and uhubctl says it will try to handle that automatically unless disabled with -e. Even then, some hubs may cut data while still leaving VBUS active, so a phone might continue charging from a port that appears powered off.

Installation is straightforward on macOS, Ubuntu/Debian/Raspbian, Redhat/EPEL/Fedora/CentOS, OpenSUSE, and FreeBSD through standard package managers, though the project warns packaged versions may lag behind the latest release. It can also be compiled from source on Linux, FreeBSD, NetBSD, SunOS, and MacOS using libusb-1.0. On Windows, it compiles, but USB power switching does not work because libusb uses winusb.sys, which Microsoft says lacks the required USB control requests.

Basic usage is simple:

Recommended reading

CodeAlmanac turns chats into a living code wiki

  • uhubctl lists supported hubs
  • uhubctl -a off -p 2 turns port 2 off on the default smart hub

Supported actions are off, on, cycle, and toggle. If multiple hubs are connected, users can target a specific one with the -l location parameter.

On Linux, the project recommends either running with sudo or configuring udev permissions. It also notes that beginning with Linux Kernel 6.0, there is a standard interface for enabling or disabling USB hub ports, which uhubctl will try to use instead of libusb.

One warning stands out: turning off built-in USB ports can also cut power to your keyboard or mouse.

Tomas Berg

Computing Editor

Tomas lives in the terminal. He covers chips, laptops, and operating systems with a focus on performance and efficiency. He reads kernel changelogs the way other people read fiction, and he's always on the hunt for the perfect mechanical keyboard switch. If it processes data, Tomas has an opinion on it.

via Hacker News

// Keep reading