Source server have one owner is root.


My local machine is destination.

----/home/sub1/test1 owner by user1
----/home/sub2/test1 owner by user2

How I can sync new update file form Source server to local machine and don't change local owner?


I need to sync all source in one command because have many folder and local machine have many owner too. Maybe possible?


  • you can refer this link http://unix.stackexchange.com/questions/267352/rsync-complication-on-sync
    – AReddy
    Jun 22 '16 at 2:14
  • Should user1 also end up owning files and directories inside /home/sub1/test1 too?
    – roaima
    Jun 22 '16 at 11:34
  • 1
    Looks like chown after rsync is the only solution. It always set ownership for transferred files.
    – Putnik
    Jun 22 '16 at 13:55
  • I give up for this yet maybe is only can chown after rsync for my solution like Putnik said. Jun 25 '16 at 12:37

It sounds like that you do not want them to change after the transfer.

Try below command:

rsync -avr -o -g /source/directory user@:destinationHost/destination/directory

If you don't use these options, the user and group will be changed to the invoking user on the receiving end. If you want to specify some other user, you will need to add a chown command to your script.

-o, --owner
    This option causes rsync to set the owner of the destination file to be 
    the same as  the source file, but only if the receiving rsync is being run 
    as the super-user (see also the --super and --fake-super options). Without 
    this option, the owner of new and/or transferred files are set to the invoking 
    user on the receiving side...

-g, --group
    This option causes rsync to set the group of the destination file to be the same as 
    the source file. If the receiving program is not running as the super-user (or if
    --no-super was specified), only groups that the invoking user on the receiving side
    is a member of will be preserved. Without this option, the group is set to the default
    group of the invoking user on the receiving side...

SEE MAN rsync
  • Thanks you that not work for me. For your command source server mush have user and group same local server. But I have 100 user it hard to do. Thanks. Jun 25 '16 at 12:39
  • 3
    I know this is old, but for others that stumble on this, the destination server must know of the users for -o and -g to work. Also, -a already includes -o and -g Mar 18 '20 at 1:38

I think a good option for you might be to just rsync from source to destination normally, assuming it's a separate physical file-system transfer, using something like

rsync -e 'ssh -p 22' -quaxz --bwlimit=1000 --del --no-W --delete-excluded --exclude-from=/excludedstufflist /sourcedir serverIP:/destinationdir

and then when it's all copied to the right place on the new system, find out what new UIDs your system gave the data from the source system. It's probably 1001, 1002 etc. In which case you can easily do a

find /destinationdir -user 1001 -exec chown username '{}' \;
find /destinationdir -user 1002 -exec chown otherusername '{}' \;

Yes, you'd have to do that last thing 100 times, but you could easily script that, if you know the UID sequence used during rsync.. I've done exactly this once, migrating about 60 users from one server to another, and it worked reasonably well. I also needed to replace group permissions, similar deal;

chown --from=oldguy newguy * -R
chown --from=:friends :family * -R

Stuff like that. Hope you can use this.


You can't do this in one command. However, even with 100+ users it's pretty straightforward to automate the task, so I don't see why you're insistent it has to be one command.

You need to pull the data from the destination machine in this scenario. It would theoretically be possible to drive the transfer from the source server by tunnelling an rsync over a reverse ssh tunnel that that would be considerably more complicated.

for testdir in /home/sub*/test1
    owner=$(stat -c %u "$testdir")
    rsync -avP --chown "$u" sourceserver:"$testdir"/ "$testdir"/

If you don't have the --chown flag you can emulate this with a two step process:

for testdir in /home/sub*/test1
    owner=$(stat -c %u "$testdir")
    rsync -avP --no-owner sourceserver:"$testdir"/ "$testdir"/
    chown -R "$u" "$testdir"                   # If possible
    # find "$testdir" -exec chown "$u" {} +    # Otherwise

If you need to use the find variant and your find does not understand +, replace it with the slightly less efficient \; (that's backlash semicolon).

  • Thanks for the loop. Im doing this on Mac but no --chown flag. Does Unix/Linux rsync have a --chown option? I did not see that on the linuxcommand.org/man_pages/rsync1.html . Yet, the loop could still add the chown task right after the rsync.
    – ndasusers
    Dec 13 '16 at 13:46
  • @ndasusers alternative solution provided for you
    – roaima
    Nov 5 '17 at 16:46

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.