Rsync and www-data permissions

I’ve recently installed NextcloudPi and have been using rsync to send data from my laptop to my RP. This all works great but I then end up having to use chown/chown to change the permissions on /media/USBdrive/ncdata back to www-data from pi. I’ve been using this as my rsync command from my laptop to my RP, ‘rsync -azvh /data/to/backup/ root@:/media/USBdrive/ncdata/ncp/files/backedUpData/’. Is there a way to rsync and not have to change the permissions on the NCP instance each time?

rsync -azvh /data/to/backup/ www-data@:/media/USBdrive/ncdata/ncp/files/backedUpData/

Thanks. Wouldn’t I need to know the password for www-data which is the default user that runs the web server?

sure. you can set one. and allow password authentication in /etc/ssh/sshd_config.

nevertheless is more wise to setup a ssh keypair for the user www-data.
e.g. https://www.digitalocean.com/community/tutorials/how-to-set-up-ssh-keys--2

and you have to check the shell of the user www-data. maybe it’s set to nologin or /bin/false

Oh ok. Thanks for the link. Will give it a shot. Also looks like versions 3.1.0+ of rsync have --chown and --chmod options so may give that a try too. Thanks again for your helpful responses.