Wednesday, December 29, 2010

ssh + netcat + tar + xz = Secure Network Transfer Link

I found a way to use simple command-line tools to transfer files between computers far apart. Using this method, I was able to duplicate the contents of an entire filesystem securely over a SSH tunnel between two computers. In this method, no NFS server or scp command is needed. However, netcat plays an important role in this method. Let's first make sure we have everything ready.



  • OpenSSH
  • netcat
  • tar or cpio
  • xz, lzma, lzo, bzip2 or gzip


I'll be really brief.




  1. At the computer where you will receive files (say, 192.168.1.2), type the following commands to start netcat in listening mode and use tar + xz to unpack the incoming stream of data.



    cd /my/downdoad/folder
    nc -l 7749 | xz -dc | tar xvf -


  2. At the computer where you will send files (say, 192.168.1.1), create a ssh tunnel to the computer receiving files (192.168.1.2).



    ssh -l username -L 5525:192.168.1.2:7749 192.168.1.2


  3. Open another terminal window and type the following command to start sending files.



    tar cvf - . | xz -c | nc 127.0.0.1 5525


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.

About This Blog

KBlog logo This blog seeks to provide a collection of interesting pictures found on the Web. Thanks for visiting the blog and posting your comments.

© Contents by KBlog

© Blogger template by Emporium Digital 2008

Followers

Total Pageviews

Powered By Blogger