I want to rsync a sub-directory from one system and place it on a remote host in the same parent directory (that does not exist) on the remote host. If I use rsync as root and specify chown the sub-directory ownership is correct on the remote system but the newly created parent directory is not, the parent directory ends up being root owned. I have to do this as root due to some permission issues that violate ssh security rules (not allowing me to use keys with the target account on the remote host).


System A:

  • bob123:bob123 755 - /home/bob123/configurations/
  • bob123:bob123 755 - /home/bob123/configurations/app1/
  • bob123:bob123 755 - /home/bob123/configurations/app2/
  • ...

System B:

  • bob123:bob123 755 - /home/bob123/ (THIS DIRECTORY IS EMPTY)

As root on system-A:

rsync --chown=bob123:bob123 -IHrlptD /home/bob123/configurations/app4 system-b:/home/bob123/configurations/

The result is:

  • root:root 755 - /home/bob123/configurations
  • bob123:bob123 755 - /home/bob123/configurations/app4

I've tried different options but haven't yet found the one that works and system-b:/home/bob123/configurations is always root owned while the app4 directory tree ownership and permissions are correct (owned by bob123:bob123).

If push comes to shove, I could use ssh to run a mkdir, but was wondering if it is possible to use just rsync to do what I want.

Update: Not sure if it matters, but the systems are Ubuntu 18.04 using rsync 3.1.2 and OpenSSH_7.6p1.

############ Solution: ############

Thank you @roaima for the help!

The -R option and /./ were the missing options. I also had to include the -go options as well.

I ended up with something like the following:

rsync --chown=bob321:bob321 -IHazR /home/bob123/./configurations/app4 system-b:/home/bob321/

If the same user exists on both systems I don't have to use --chown but for a remote system with a different process owner in play it is. The above example is making use of chown to reflect the different usage. In my script the chown option setting is dependent on the remote host address.

Again, thank you @roaima for pointing me in the right direction with the -R option!

1 Answer 1


Your command (simplified here) does not include configurations in the list of directories to be transferred, so the transfer rules such as chown do not apply

rsync -a /home/bob123/configurations/app4 system-b:/home/bob123/configurations/

Given that /home/bob123 already exists on the destination, rsync will create a single further directory to match the target /home/bob123/configurations. It will then copy the source app4 file or directory tree into that newly created target directory.

If you want configurations to be included in the list of transferred directories you can use the -R (--recursive) flag and include the source configurations directory in the transfer tree

rsync --chown=bob123:bob123 -IHrlptDR /home/bob123/./configurations/app4 system-b:/home/bob123/

Another way of handling this is to log in as bob123 on system-b, so that everything is implicitly owned by the target user:

rsync -Ia /home/bob123/configurations/app4 bob123@system-b:configurations/

PS Do you really want -I (--ignore-times)? Unless you know for certain that you need this flag, do not use it.

  • Thank you Roaima for the feedback and examples. I'll give the -R option a try. Yes, the -I option is needed due to how some of the source files are moved into place and when they were first generated. If the remote image is remastered doing a pull vs a push would be a better option. Regards, Bob.
    – Bob
    Jul 14, 2021 at 23:39
  • -R is working but I also had to include the -go options. I had stopped using -a because I had thought that the go options were messing me up. The other key from your example is the use of the /./ in the source path. I've check the man page again and now understand where I went wrong. I appreciate the help. Thank you!
    – Bob
    Jul 15, 2021 at 0:13

You must log in to answer this question.

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