2

So I have this workflow which works but is clumsy"

RSYNC to ultrapress.co

rsync -azP --delete /Users/rocketadmin/Sites/vagrant-local/www/wordpress-default/wp-content/themes root@107.170.237.162:/var/www/ultrapress.co/htdocs/wp-content/

rsync -azP --delete /Users/rocketadmin/Sites/vagrant-local/www/wordpress-default/wp-content/plugins root@107.170.237.162:/var/www/ultrapress.co/htdocs/wp-content/

=============================================================

Then REPAIR ownership

sudo chown -R www-data:www-data /var/www

I'd like to know what arguments to use in rsync so I don't have chown my www folder everytime I sync Thank you in advance for your guidance...

Yoyo
  • 21

4 Answers4

2

You have 3 ways of doing this:

  • Give SSH access to www-data and rsync using www-data user. This is highly not recommended but, if you do it with much care (block all SSH access except from your own IP, use an SSH key and remove the password for the www-data user), it may as well work.
  • Create a user and group on your local PC with the same names and numeric user IDs as the ones on your server and make sure that all files have these as owner before rsyncing (the -a flag that you are already using does this).
  • Make a wrapper script for rsync on the server that does the chown right after the rsync is done, then use --rsync-path argument for the client.
2

You can use sticky bits to make sure that everything that is created under /var/www/ultrapress.co would be owned by www-data user/group.

To do this, on the server set these permissions:

chown ultrapress.co www-data:www-data
chmod u+s ultrapress.co
chmod g+s ultrapress.co

Now whenever any user will make a new directory or file in this directory, it will have www-data's user and group.

You can also set the sticky bits on all of the existing subdirectories with:

find ultrapress.co -type d -exec chmod u+s,g+s '{}' +

Or alternatively, set sticky bit to /var/www directory:

chmod u+s,g+s /var/www
ek9
  • 2,131
2

If you have access to rsync v.3.1.0 or later, the --chown option should be what you're looking for:

rsync -azP --chown=www-data:www-data [src] [dst]

Note: the -o and -g options are required for it to work, but of course, already included via the -a option you've set.

More info can be found via an answer on a similar question here: Rsync command issues, owner and group permissions doesn´t change

1

My usual approach when doing this sort of thing is to do

rsync <options> www-data@remote-host

I then use SSH-key authentication for www-data on the remote server.

Personally I run the local script as www-data too, as I find that more logical.