24

I have two machines with Ubuntu 14.04, right next to each other. But no network ((W)LAN). Can I transfer data from one machine to the other via usb-cable? And if so, how?

muru
  • 193,181
  • 53
  • 473
  • 722
Creech
  • 361
  • 1
  • 2
  • 5
  • 1
    No, I don't think so. You'd need something called "bridged cable" for that. – mikewhatever Apr 17 '17 at 19:07
  • 1
    In general, no. USB was designed to be PC-to-peripheral. We've blurred the definition of peripheral with tablets and phones, but you can't plug a plain old USB A-to-A cable from PC-to-PC. I don't believe I've ever seen an A-to-A cable aside from the Windows Easy Transfer Cable. – Christopher Hostage Apr 17 '17 at 21:41
  • 3
    What has been said is true for ordinary PC's, though strictly speaking "Ubuntu 14.04" does not identify hardware, and there may well be builds that run on various quasi-embedded platforms or tablets that have USB device or OTG interfaces, as well as the USB host interfaces common on PC's. – Chris Stratton Apr 17 '17 at 21:45
  • 2
    This has been answered at https://superuser.com/a/1165890/41259 . – chx Apr 18 '17 at 01:40

4 Answers4

16

When you say, USB cable you are referring to a Windows Easy Transfer Cable, right?

enter image description here

In that case, the easiest way to do this is to just hook the two machines directly together with an Ethernet cable. Modern NICs are smart enough that you don't even need a crossover cable; they just automatically crossover when they detect that you connected two computers.

You'reAGitForNotUsingGit
  • 14,669
  • 9
  • 48
  • 83
  • 3
    From what I've heard, USB transfer cables as pictured are typically treated as a type of network in Linux anyway. Some ultralight laptops don't have wired ethernet jacks, so this could be advantageous - the option might be two USB-Ethernet adapters and an RJ45 patch cord (but though those could then be used for other networking purposes, too). – Chris Stratton Apr 17 '17 at 21:48
  • 1
    @ChrisStratton That's correct. These cables are essentially two NICs. – David Schwartz Apr 17 '17 at 22:25
  • 1
    @DavidSchwartz in terms of how Linux traditionally treats them, yes. But Windows sees them completely differently (reportedly cross platform transfer does not work) and architecturally they are probably a pair of FIFOs and some logic sitting between two USB device engines, or even just coordinating logic to create virtual fifos out of a common buffer memory. – Chris Stratton Apr 17 '17 at 23:09
  • 2
    @ChrisStratton They're pretty much all based on some variant of the Prolific 2501 (2301, 25A1, whatever). Physically, there's two FIFOs between two backend controllers with a microcontroller for management. But that's essentially the same as what you'd get if you connected two NICs to each other. How the driver chooses to present it is, of course, the driver's choice. The same Windows software that works over these cables typically also works over back-to-back NICs unless the manufacturer chose to lock it down. – David Schwartz Apr 17 '17 at 23:27
  • This, I believe, is the USB 2.0 answer with the USB 3.0 answer being at https://superuser.com/a/1165890/41259 . – chx Apr 18 '17 at 01:42
  • Did you miss "no network ((W)LAN)" in the question?" This is a valid general answer but doesn't appear to take the OP's situation into consideration. – Elder Geek May 01 '17 at 14:58
  • @ElderGeek - No network to me means that the two computers are not on a LAN together. Connecting two computers directly with an Ethernet cable does not require the two machines to be on the same LAN; in fact, it would be physically impossible to connect them directly and have them connected to the LAN simultaneously unless the OP's computer has two NICs – You'reAGitForNotUsingGit May 01 '17 at 15:08
  • @AndroidDev perhaps your right and I just have hardware on the brain this morning. It's true that the question doesn't make it abundantly clear whether they are speaking of interfaces or connections, but it does specifically ask about transfer via usb-cable... – Elder Geek May 01 '17 at 15:16
3

If you absolutely had to do this for a proof of concept you could simulate the ancient art of "laplink" transfers by emulating a serial port on each machine.

Usb to serial on one, and usb to serial (null modem) in the other, sorting out gender issues in the middle.

It would not be quick.

mckenzm
  • 355
  • 2
  • 11
1

Firewire might also be an option. https://help.ubuntu.com/community/EthernetOverFirewire

Charlie
  • 111
  • 2
0

If your machines have either a Type-B or On-the-Go connector, you can use the USB Gadget Driver. To load the driver

# modprobe g_ether

You can configure the MAC addresses and the vendor and product IDs:

# modinfo g_ether
filename:       /lib/modules/version/kernel/drivers/usb/gadget/legacy/g_ether.ko
license:        GPL
author:         David Brownell, Benedikt Spanger
description:    RNDIS/Ethernet Gadget
srcversion:     5E4C828D24F6E477C9CB5EE
depends:        libcomposite,u_ether,usb_f_rndis
intree:         Y
vermagic:       version SMP mod_unload modversions 
parm:           idVendor:USB Vendor ID (ushort)
parm:           idProduct:USB Product ID (ushort)
parm:           bcdDevice:USB Device version (BCD) (ushort)
parm:           iSerialNumber:SerialNumber string (charp)
parm:           iManufacturer:USB Manufacturer string (charp)
parm:           iProduct:USB Product string (charp)
parm:           qmult:queue length multiplier at high/super speed (uint)
parm:           dev_addr:Device Ethernet Address (charp)
parm:           host_addr:Host Ethernet Address (charp)
parm:           use_eem:use CDC EEM mode (bool)

You can set module parameters when loading the driver by passing them after the module name:

# modprobe g_ether host_addr=00:dc:c8:f7:75:05 dev_addr=00:dd:dc:eb:6d:f1

If neither of your machines support operation as a USB device, this approach will not work.

Warning: DO NOT attempt to connect two USB Type-A connectors. At best, you may damage your motherboards. At worst, you may start a fire.

  • there is a perfectly safe and logical reason for connecting two Linux computers by a USB A-to-A cable. That is to set up a kernel dubug port. https://www.kernel.org/doc/html/v5.4/driver-api/usb/usb3-debug-port.html This has been part of the USB spec for nearly a decade. It would be nice to see this feature be used more generally, as in outside of just a kernel debug port. The hardware is there, much of the software is there as well, if we get people used to the idea of using USB to USB connections for more than debug then maybe I'll stop seeing people ask this same question. – MacGuffin Sep 13 '20 at 02:06
  • That only applies to USB 3.0. While it may be part of the spec, I still haven't seen a USB 3.0 A-to-A cable in real life. And this is absolutely dangerous with a USB 2.0 A-to-A cable. –  Sep 13 '20 at 06:36
  • If we are going to step into the realm of suggesting USB gadget drivers then to be comprehensive, or perhaps annoyingly pedantic, then we should consider USB 3.x A-to-A cables, which has been part of the USB spec since 2010, and USB-C, which has been part of the spec since 2014. Most any computer made in the last 5 years should support USB 3.x, have USB-C ports, or both, and therefore be capable of data transfer from computer to computer by USB. The problem I'm seeing is finding the correct settings and drivers among the outdated USB 2.0 gadget information that is in abundance on the web. – MacGuffin Sep 14 '20 at 07:11