Hamid Fadishei's Blog

April 7, 2012

Transferring A Directory Tree Between Servers Using rsync without Passwordless SSH

Filed under: Linux — fadishei @ 7:29 am
Tags: , , , ,

Linux server administrators occasionally need to transfer files between servers. scp is a handy command line for this purpose. But there is a better approach, rsync, which will give you two advantages: First, you can resume broken transfers (even in case of multiple files and directories). Second, it skips transferring the files that are similar between source and target. Thus you may re-transfer content after modifications optimally.
rsync uses an externall remote shell, ssh in the case of this tutorial. One annoying thing is that many tutorials over the net require you to setup passwordless SSH (public key encryption) from between source and target machine which, in my opinion, is a real chore to be done as a prerequisite for a simple file transfer.
Instead, I suggest using sshpass utility which allows you to enter ssh password in command line. Don’t worry for you password being stored in bash_history! Linux has a solution for this: add a blank character at the start of the command and it will never go into ~/.bash_histry.

$ sudo apt-get install sshpass
$ [type a blank here] nohup rsync -avzl -e "sshpass -p dst_pass ssh" /path/to/src dst_user@dst_ip:/path/to/dst &

nohup is used to let you logout after issueing the command without the transfer operation being stopped. You may monitor the transfer progress at any time by using this command:

$ tail -f nohup.out

Create a free website or blog at WordPress.com.