5

I'm trying to run rsync to copy files (Centos 5.2 -> Centos 5.2) and I need run using nohup it so it can run after I disconnect my ssh session. The problem is I cannot get rsync to not prompt for a passowrd, and I cannot get nohup to play nice with the password prompt.

rsync -v -r -x --password-file=/root/password.txt /sourcedir/ root@10.1.1.1:/destdir

I've tried both setting the RSYNC_PASSWORD variable to the password and creating a file with the password and using --password-file, but in both those case I still get the prompt asking for the password.

How do I give rsync the password it needs to it will run happily?

10

You can use public/pricate key authentication.

Generate a pair public/private key with

ssh-keygen -t rsa

then copy dsa.pub into .ssh/authorized_keys file in your home directory in the destiny host.

7

The problem is that RSYNC_PASSWORD as well as --password-file only is applicable when connecting directly to a rsyncd server, not when spawning rsync using a remote shell such as ssh. Your choices are, depending on the data you are transferring, to either to setup password-less ssh keys or to start using a rsyncd daemon instead.

(Note that if you connect directly to a rsyncd then your data will be transfered unencrypted.)

3

Alternatively you could use screen instead of nohup. It works like this :

  • type screen
  • you will be presented with a new terminal
  • start you're command that will take forever, the rsync command in your case.
  • disconnect from your screen terminal with ctrl-a, followed by d
  • you can exit now or do other stuff, your screen terminal will go on doing your stuff
  • you can reconnect to screen, by typing screen -r, this alose works from another tty or ssh connection or whatever.
  • 1
    Or you could just use a ssh key. – Ignacio Vazquez-Abrams Jul 6 '10 at 9:34
  • There are instances where we must backup or otherwise automate file transfers from systems which are legacy, or for whatever reason do not support SSH keys. – Charlie Schliesser Dec 11 '12 at 20:59
0

Rsync will continue to prompt for password as long as it is done over ssh server and the best possible option will be to add public key authentication for ssh. So to start with :

on the source server -

$ ssh-keygen
$ Enter passphrase (empty for no passphrase):
$ Enter same passphrase again:

Now copy the ssh public key at

~/.ssh/id_rsa.pub

on to the remote host at:

ssh-copy-id -i ~/.ssh/id_rsa.pub user@host

or alternatively you can install ssh-pass and run:

SSHPASS='myPassword'
/usr/bin/rsync -a -r -p -o -g --progress -s -u --rsh="/usr/bin/sshpass -p $SSHPASS ssh -o StrictHostKeyChecking=no -l root"  /sourcedir/ root@10.1.1.1:/destdir  >&2

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.