Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I often need to transfer files over my home network between computers and have found that WiFi transfers really aren't the best idea. (facepalm) If I have a CAT-5, 5e, or 6 cable lying around, how can I connect one computer directly to the other with it? If a SSH server is running on server and I connect client to server using a CAT-5 cable directly between the two, can I then use SSH to transfer files? What do I need to do in order to set something like this up? Is a router required?

share|improve this question
up vote 5 down vote accepted

If at least one computer's network card supports auto-crossover, you can connect both with a direct cable. (Auto-crossover, also called "auto-MDIX", is part of the Gigabit Ethernet standard, but is very often supported by 100 Mbps cards too.) Otherwise, you'll need either a cross-over cable, a hub, or a switch.

After setting up the physical connection, configure networking in the OS:

  • If both ends have IPv6, you can just connect using the other computer's link-local address; for example, ssh fe80::4a5d:60ff:fee8:658f%eth0. (On Linux, the string after % is your Ethernet card's name, while Windows uses the numeric interface ID from netsh interface ipv6 show interface.)

    You can also add shorter addresses manually, such as fc00::1 and fc00::2 (from the fc00::/7 network).

  • For IPv4-only hosts, manually assign IP addresses from the same subnet – for example, 10.0.0.1/8 and 10.0.0.2/8.

    Some operating systems will automatically assign link-local IPv4 addresses in the 169.254.0.0/16 range.

share|improve this answer
    
+1 for considering IPv6 :) – Hennes Nov 25 '12 at 23:31
    
If you hadn't recommended IPv6, I never would have considered using it. Spot-on, using IPv6 features for the win! – Naftuli Tzvi Kay Nov 26 '12 at 20:29
1  
An update: just transferred a file at 70 megabytes per second for the win. – Naftuli Tzvi Kay Dec 3 '12 at 21:36

I'd recommend you use an rsync server on one of the machines to avoid the encryption processing of ssh which might give you faster throughput, especially on low-speed CPUs:

On the "server" machine, create yourself an rsyncd.conf file containing something like:

[download]
comment =       Storage general files
path =          /home/user/Download
read only =     false
write only =    false
list =          true
incoming chmod = Du=rwx,go=rx,Fu=rw,go=r
uid =           user
gid =           user

Then fire up rsync in "server" mode:

sudo rsync --daemon --config=rsyncd.conf  --no-detach --log-file=/dev/tty

Then on the client, to receive:

rsync rsync://host/download/file-name local-file-name

or to send:

rsync local-file-name rsync://host/download/file-name

When you've finished, just CTRL-C the server process.

share|improve this answer
    
Very easy to follow solution. Thanks and +1 from me. I find doing all the samba, nfs and whatnot to tedious for a simply file transfer. Also nice tip for the exclusion of the encryption process! – rbaleksandar Aug 10 '15 at 21:52
    
@rbaleksandar: Thanks. Now that I have gigabit ethernet at home, I find I can generally exceed 100MB/sec with this technique whereas scp or rsync over ssh tends to max out at 20-40MB/sec. An even simpler technique is to use netcat (nc) directly on both machines. – Adrian Pronk Aug 10 '15 at 22:12
    
Will give it a shot. And yeah, the speed is really nice. Just transferred a an ISO of like 8GB in no time. :3 – rbaleksandar Aug 10 '15 at 23:52

The short version of it is:

  • If at least one of the computers has a gigabit interface, or one supports MDI/MDX no router is required. Plug in a plain CAT5E or better cable.
  • Of both have 10/100mbit cards use a cross-cable or two regular cables and a switch.

Next configure both computers to be in the same subnet and set up routing. (See this on our sister site: how-does-ipv4-subnetting-work for the background).

You did not mention which OS you are using, but assuming a unix like:

  • Computer 1: ifconfig em0 192.168.0.1 netmask 255.255.255.0 (replace em0 with the name of the interface).
  • Computer 2: ifconfig em0 192.168.0.2 netmask 255.255.255.0
    Both network cards are now configured in for the same LAN.
  • Your OS is likely to 'automagically' add routes to the local network. If not use route add -net 192.168.0.0 mask 255.255.255.0 192.168.0.1 on computer 1. Do the same on computer 2 with route add -net 192.168.0.0 mask 255.255.255.0 192.168.0.2

Test the connection with ping or copy with scp.

(Client:~homedir> scp myfile 192.1.68.0.2:Destination_folder)

share|improve this answer
    
I don't seem to get an automatically added route (Xubuntu 14.04) - after setting the IPs, trying to ssh to the other computer gives me "ssh: connect to host 192.168.0.2 port 22: No route to host". And using your route add command gives me the Usage info for route, so presumably there's something wrong with the syntax. – weronika Feb 7 at 2:34
    
It haws been a while since I posted it and I do not recall if I tested this in a VM with Linux or on FreeBSd. Will check when I am home with both OS's and add working syntax for both. – Hennes Feb 7 at 11:33

You will either have to set up a bridge on server (S) with the usual network and then connect the client (C) to said network (IP-wise) or use a custom subnet. The latter is pretty straightforward (with eth0 being the connected interfaces on the client and server):

C # ip addr add 10.0.1.2/24 dev eth0
S # ip addr add 10.0.1.1/24 dev eth0

at this point, C # ping 10.0.1.1 should work. If the SSH server on S is configured to listen on all interfaces (i.e. 0.0.0.0), you should be ready to go, otherwise you will have to make it listen there (by adapting /etc/ssh/sshd_config).

If you don't get the speeds you expect, make sure (via ethtool eth0) that the connection speed has been detected properly. You can change it using the same tool.

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .