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

Leave a Comment »

No comments yet.

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at WordPress.com.

%d bloggers like this: