3

I'm just trying to copy a directory from one home server to another, both running Ubuntu (9.04 and 9.10), using rsync. The trouble I'm having is that some of the files in the directory (and subdirectories) are owned by root. The main administrator account on both machines is 'ben', so running this on the old server:

rsync -v -u -a -p -t -rsh=ssh --stats --progress source/ ben@newserver:/dest

Prompts me for ben@newserver's password, copies source/ but all the permissions are 'ben' at the new destination. Running this using sudo means I have access to root's files, but on the other end ben can't write them as belonging to root. Sending to root@newserver asks for root's password, which Ubuntu doesn't give you.

Can anyone explain simply how to do this? Thanks :)

3 Answers 3

5

You can set up SSH keys, and place your public key in root's ~root/.ssh/authorized_keys2 file on newserver. That way you can do the entire process as root.

Alternativly you can set root's password via:

sudo passwd root

But SSH keys are more secure and (IMHO) more convenient.

3
  • I've done the first part; I can now 'ssh root@newserver' successfully without being prompted for a password, but running 'rsync source/ root@newserver:/dest/' asks for root's password still, and therefore fails. Any idea why that would be the case?
    – Ben Hymers
    Nov 1, 2009 at 17:59
  • Ne'er mind, I just gave root a password as you also suggested. I'll remove it once I'm done - it's just a one-off backup on internal machines. Sorry to the other answers though - apparently voting up requires 15 reputation, which I don't have yet!
    – Ben Hymers
    Nov 1, 2009 at 19:53
  • Glad you got it working. It might have been that root on the old server didn't have access to the private key (because it was in ~ben instead of ~root). But no need to troubleshoot it as you got it working!
    – Josh
    Nov 2, 2009 at 13:18
3

You can use the --rsync-path option to run sudo rsync on the remote machine; I suspect you'll have to give the ben user passwordless sudo privileges to run rsync, as the chances of rsync-path passing the password prompt back to the source machine are slim.

1
  • I found that the prompt made it back to the local machine, but entering the password didn't make it to the remote machine.
    – Tim Abell
    Apr 28, 2010 at 8:53
1

In order for rsync to maintain all file ownership/permissions attributes it need to be running as root at the end that is being written to. If you are only root at one end, this needs to be the writing end, so you would need to do

rsync -v -u -a -p -t -rsh=ssh --stats --progress user@oldserver:source/ /dest/

while logged in as root on the new server.

The --fake-super option can be useful when sending files to a backup location where you do not have root access (and when getting the files back again afterwards) but that won't be applicable here without a little extra mucking about (rsyncing to an intermediate location on either server with that option, then rsyncing to the final destination with it too).

The other options, as already mentioned, is to give your user at the writing end passwordless access to rsync as root in your sudo config.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .