Ever wondered how to connect two computers together without going through a local network (LAN)?
If your computers are on a network, you can share files and folders, but what happens if you don't have a router/switch/hub to make that LAN happen?
In this tutorial I will show you how to use a crossover cable to connect two computers and transfer data.
DISCLAIMER: I've made this tutorial using Linux.
Step Zero : Requirements
- Administrator access to both computers.
- A crossover ethernet cable.
Step 1 : Make (and plug) a crossover cable
Once you have your cable settled, connect it to the computers.
Step 2 : Set a static IP address on both computers
Even if we had both computers connected to a LAN, we are not using the same network addresses. With the crossover cable we are creating a little peer-to-peer connection, and that is a completely different network. For this case, the best solution is to configure a static IP address for each computer (within that new network we're creating).
Check out the tutorial How to Set Static IP Address in Linux to see it in detail.
Make sure that both computers are on the same subnet (like 192.168.1.1 and 192.168.1.2) and use the same mask (like 255.255.255.248).
There are two possible configuration files in Linux systems (consider
eth0 as Ethernet interfaces):
With that ready you can do the first test:
That confirms both sides are connected and seeing each other.
Step 3 : Security measures (firewalls and user accounts)
The computers see each other but they can't do anything yet. For that you have to open their conversation by allowing incoming SSH connections from one another.
UFW (Uncomplicated Firewall) is used for managing a Linux firewall.
Open ports on the firewall: using
ufw we will open port TCP/22 for the other computer (PC1 to PC2, PC2 to PC1 or both).
To allow incoming SSH connections from a specific IP address named 192.168.1.2, enter:
sudo ufw allow from 192.168.1.2 to any port 22
To enable ufw:
sudo ufw enable
To check the status:
sudo ufw status
ufw was not enabled the output would be:
sudo ufw status Status: inactive
Step 4 : Enable SSH
Secure Shell (SSH) is a cryptographic network protocol used for an encrypted connection between a client and a server.
You can enable the SSH server for one or both computers, but the SSH client creates a secure connection only to the machine that have the SSH server daemon (sshd) running.
Check out the tutorial How to setup and use SSH Server on Linux to see it in detail.
Step 5 : Use SFTP
For file transfer you can use FileZilla, that runs in server and client versions in different platforms (including Windows, Mac and Linux). Or, if you are using Linux or Mac, SFTP is a good choice.
SFTP (SSH File Transfer Protocol) is a secure file protocol that is used to access, manage, and transfer files over an encrypted SSH connection. SFTP works on a client-server model.
In this tutorial scenario, open a SFTP connection to the other computer: use the
sftp command followed by the username and the IP address:
You will be prompted to enter the user password. Once connected, you will be presented with the
sftp prompt, and you can start interacting with the remote server:
Connected to email@example.com sftp>
get to download files and
put to upload.
sftp> get remote_file.txt Fetching /home/demo/remote_file.txt to remote_file.txt sftp> put local_file.txt Uploading local_file.txt to /home/demo/local_file.txt
In this tutorial you learned how to use a crossover cable to connect two computers running Linux and transfer data using SFTP.