Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 :)

share|improve this question
up vote 5 down vote accepted

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.

share|improve this answer
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 '09 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 '09 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 '09 at 13:18

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.

share|improve this answer
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 '10 at 8:53

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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