At the crude end you could probably use a relay board.
hmmm, you RAAAANNNNNGG? (yes finally a reason validating my existence!)
Sorry, but I just couldn't resist chiming in on this topic. So what I can add is:
I have a Teensy 3.2 - RPi2 contraption at a site which is impersonating a
USB mouse, from the security NVR's perspective (think Fred Sanford meets Frankenstien) And since I just couldn't grok using the serial UART (I think) I did everything using relays and optocouplers. So I SSH my way into the RPi's using Putty to initialize a VNC connection (just once per restart; although ugly, this sure beats the trauma of BASHing commands into RPi which elf up its bootup behavior to autostart VNC) So now instead of dreary CLI hell I have an ARM friendly release of the latest Arduino 1.6.13 IDE(emphasis on GUI !!) which (as of like the last few months) NOW SUPPORTS Teensy 3.2 with Teensyduino! (meaning support for teensyloader as well) Pretty slick, huh? Write Arduino sketches "anywhere on earth" with full GUI support and flash them onto a Teensy (well at least it's impressive to me...)
OK, so now comes the crude hacking of ugly relays I salvaged dumpster diving (that's pronounced "F-R-EE") The flaw in my setup is how to get the freshly programmed Teensy to change hosts? So I built an mechanical A-B switcher (2 hosts sharing a single client). Originally I was way cautious so I used four double pole relays for pluging/unplugging in a 5 step process controlled by three of RPi's GPIOs. USB power supply lines from the Teensy feed the poles on a DPDT relay, disconnecting Teensy from all power if energized. N.C. contacts feed the poles on another relay that selects one of two hosts. The N.C. contacts on this relay feed the NVR, so that if control circuitry fails to deliver power to any given relay coil, the "normal" contacts default to Teensy being fully connected to the NVR, which normally doesn't shut down. The Rx & Tx lines were wired the same way.
When jumping from host to host, I used the rule for PA amplifiers to remember: last to power up, first to power down. The five step sequence is derived from this rule, which is:
ENERGIZE SIGNAL RELAY,
ENERGIZE POWER RELAY,
TOGGLE SWITCHING RELAY,
KILL POWER RELAY,
KILL SIGNAL RELAY This is the weakness in my system, because I use the same script regardless of the host. The middle step is just "toggle" and led to a sloppy protocol. Rigorous fool-proofing shouldn't allow a script to end with the A-B selector having an energized relay since the fall-back safety configuration was hard-wired for all relays being in their normal, unenergized state. As long as a relay is energized, the script keeps running would be best practice. So, being lazy and absent-minded, it wasn't long before I rebooted the RPi with the Teensy still attched. Sheer terror. And the next time, merely anxiety. Subsequent breaches of protocol became simple annoyances. So now, protocol is a joke, reboot has all the dignity associated with an episode of Jersey Shore! (translation the signal/power concern hasn't been an issue in this situation)
Bottom line, mechanical port switchers have worked great for me. After the Teensy project is complete, I plan on using it to switch a USB drive between the NVR to archive important files, and a RPi for file sharing over the web. And remember, mechanical switchs (with relays belonging to the family) are still superior to Silicon based devices in many way. For example, leakage current in mechanical switches is almost nil, they have no polarity constraints, consume no current, and produce no noise in a static state.
And finally, regarding this passage:
Another tactic could be to get one of the hubs with buttons, take it apart, and wire a relay across one of the buttons.
I'd like to share a gem I unearthed on eBay: a finer link you cannot find and is as fresh as today's date. So here's a hub that I think matches your description:
Yes, that a 7 port hub with a toggle switch and indicator led on each port. Delivered right to your door for the tidy sum of US$3.01 What kind of numbers does it benchmark at? Hmmm. you might be missing the point. It's a 7 port UBS hub with bells $ whistles with FREE SHIPPING for 3 BUCKS !!!