I'm setting up rsync to transfer files from ServerA to ServerB, and need to preserve timestamps and permissions. They key here is the files are owned by a different account than the one performing the file transfer.

rsync transfers files using the example below:

rsync -a /colorschemes/ acoder@bu.my.box.net:/colorschemes/ --delete

The -a flag yields the following types of errors:

rsync: failed to set times on "/colorschemes/946/ex": Operation not permitted (1)
rsync: failed to set permissions on "/colorschemes/946/ex/blue.pdf": Operation not permitted (1)

On the remote system, the acoder account has a similar error when attempting to manually set permissions on a file:

[acoder@bu ~]$ chown apache:codingteam /colorschemes/946
chown: changing ownership of ‘/colorschemes/946’: Operation not permitted

This works OK, though:

[acoder@bu ~]$ sudo chown apache:codingteam /colorschemes/946

Is there a way to make the remote rsync use sudo?


For using sudo with rsync in remote machine you can call it with --rsync-path="sudo rsync" but be aware of the require TTY, you skip it by removing Defaults requiretty from sudoers file.

If you want to change the permission for anything you don't own, you have to use sudo if you were not root

or there is a different way like setting a setuid on chmod, chown then any one can run the chmod, chown as a root, but that will be horrible.

  • @acoder i edited my question so u add a way to do that – Wissam Roujoulah Dec 12 '16 at 15:43
  • @acoder you can use sudo with --rsync-path="sudo rsync" but make sure you make the user acoder require no password for using rsync with sudo – Wissam Roujoulah Dec 12 '16 at 15:55
  • Ok, so --rsync-path is used to set the path of rsync on the remote computer. Will try that and follow up. – a coder Dec 12 '16 at 15:59
  • "sudo: sorry, you must have a tty to run sudo" – a coder Dec 12 '16 at 16:01
  • Ok so this answer says it's safe to remove the Defaults requiretty line from the sudoers file. Gave that a go, and it worked. unix.stackexchange.com/a/122624/20107 – a coder Dec 12 '16 at 16:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.