Rsync command issues, owner and group permissions doesn´t change

Solution 1:

Version 3.1.0 of rsync introduced the --usermap and --groupmap mentioned by Thomas, but also the convenience option --chown, which works well for your scenario.

--chown=USER:GROUP
    This option forces all files to be owned by USER with group GROUP.
    This  is  a  simpler  interface  than  using  --usermap  and  --groupmap directly,
    but  it  is implemented using those options internally, so you cannot mix them.
    If either the USER or GROUP is empty, no mapping for the omitted user/group will
    occur.  If GROUP is empty, the trailing colon may be omitted, but if USER is
    empty, a leading colon must  be supplied.

    If you specify "--chown=foo:bar, this is exactly the same as specifying
    "--usermap=*:foo --groupmap=*:bar", only easier.

Also, the -o and -g options are required. Excluding them will fail to update their respective attribute, but produce no error.

rsync -og --chown=cmsseren:cmsseren [src] [dest]

This is mentioned indirectly in the manpage, which states that the --chown option "is implemented using --usermap and --groupmap internally", and:

For the --usermap option to have any effect, the -o (--owner) option must be used (or implied), and the receiver will need to be running as a super-user (see also the --fake-super option).

For the --groupmap option to have any effect, the -g (--groups) option must be used (or implied), and the receiver will need to have permissions to set that group.

Solution 2:

It sounds like it is working correctly. Use --owner and --group to preserve (not set) the owner and group names... meaning that you do not want them to change after the transfer.

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...

man rsync


Solution 3:

Last version (at least 3.1.1) of rsync allows you to specify the "remote ownership":

--usermap=tom:www-data

Changes tom ownership to www-data (aka PHP/Nginx). If you are using Mac as the client, use brew to upgrade to the last version. And on your server, download archives sources, then "make" it!

Tags:

Linux

Ssh

Rsync