Running rsync as root from bash script

62 Views Asked by At

I have a bash script that is created under a user account and calls rsync to sync two directories.

However I need rsync to be able to also sync a directory from another user account.

The bash script is called with a crontab timer ever month from the user account.

If I add rsync line to sync the second directory from the other user account to the bash script I get a permission denied.

How do you overcome this? Does rsync need to be run as root in the bash script? How would you do this?

Tried to run as normal user but got permission denied

Or should I change the permission for the other user directory so the first user can access? If so, what is the command for this?

1

There are 1 best solutions below

0
may On

If the user has access to sudoers, adding the argument --rsync-path='sudo rsync' will allow to rsync as root.