I seem to come up against this issue occasionally:

serverA assets:
owned by user: apache
(no 'ftp' user present)

serverB assets:
owned by user: ftp
(apache user present, but not used)

I connect to serverA as root, then rsync over ssh to serverB as root. After which, all the assets on serverB are owned by either root or apache, depending on whether or not I tell rsync to preserve the ownership that the files have on serverA.

Anyone have any tricks for changing ownership of rsync'ed files on serverB to an alternate user, one that is not the owner on serverA and is not the user issuing the rsync command? The resulting files on serverB would be owned by the 'ftp' user.

In the past, I've always just followed the command with a recursive chown, but I'd like to find a way to do this in rsync, or get it down to a single command.


Try setting RSYNC_RSH to "ssh -o 'User apache'"
and/or using --rsync-path='su apache -c rsync'
or patch the rsync source to support setting abitrary users.

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.