ssh + netcat + tar + lzma = Secure Network Transfer Link
| url: | http://kemovitra.blogspot.com/2010/12/ssh-netcat-tar-lzma-secure-network.html |
|---|
I found a way to use the netcat and tar commands to duplicate the contents of an entire filesystem securely over a SSH tunnel between two computers. The method shown here doesn't need an NFS server nor does it use the scp command. Let's first make sure we have everything ready.
- OpenSSH
- netcat
- tar or cpio
- lzma, lzo, bzip2 or gzip
I'll be really brief. At the computer that will receive files, type the following commands to start netcat in listening mode and use tar + lzma to unpack the incoming stream of data:
nc -l 777 | lzma -dc | tar xvf -
At the computer that will send files, create a ssh tunnel between the two computers that you want to duplicate files on:
ssh -l username -L 555:192.168.1.2:777 192.168.1.2
At the computer sending files, open another terminal window and type the following command to start sending files:
tar cvf - . | lzma -9c | nc 127.0.0.1 555
Partition Imaging with Netcat
Backing up hard drive partitions over the network can be accomplished with just a few simple tools like netcat. This is another handy usage of netcat. At the receiving computer where you'll store the backup, type the command to receive the partition image:
nc -l 7749 | lzma -dc | dd of=/dev/sda8 bs=640K
At the sending computer from which you'll transmit the partition, establish an SSH link first:
ssh -l username -L 5525:192.168.1.2:7749 192.168.1.2
Then compress the partition data and transmit over the secure SSH channel:
dd if=/dev/sda11 bs=640K | lzma -9c | nc 127.0.0.1 5525
Note that the transfer may take many hours for a large partition.
