How to Fix “rsync failed to set permission Operation not permitted” Error When Syncing Files


2 views

The error occurs because rsync attempts to preserve file permissions by default (using the -p flag implicitly). When you don't have sufficient privileges on the remote system to modify directory permissions, this operation fails.

Simply add the --no-perms flag to your rsync command:

rsync -avz --links -O --no-perms /home/jansiatest/.jenkins/workspace/svn_to_demo/trunk/CPS/ jansia@ps27670.dreamhost.com:/home/tasklite/temp

If you need some permission preservation but want to avoid the directory permission issue:

# Preserve only file permissions (not directories)
rsync -avz --links -O --no-dperms /home/source/ user@remote:/target/

# Or use chmod to set explicit permissions on target
rsync -avz --links -O /home/source/ user@remote:/target/ && \
ssh user@remote "chmod 755 /target"

For complex synchronization needs, consider combining multiple options:

rsync -rlptDOvz --no-perms --exclude='*.tmp' \
--delete --partial --progress \
/home/source/ user@remote:/target/

The --no-perms option tells rsync not to try setting permissions on the remote files. This is particularly useful when:

  • You're syncing to a shared hosting environment
  • The remote directory has restrictive permissions
  • You only care about file contents, not metadata

While disabling permission preservation solves the immediate problem, be aware that:

  • Files will inherit the umask of the remote system
  • Sensitive files might end up with incorrect permissions
  • Consider using --chmod to explicitly set permissions if needed

When running rsync with the -a (archive) flag, the command attempts to preserve all file attributes, including permissions. This becomes problematic when:

  • You don't have sufficient permissions on the remote system
  • The target directory has restrictive ownership
  • You intentionally want to skip permission changes

The simplest fix is to modify your rsync command to exclude permission preservation:

Original problematic command:

rsync -avz --links -O /source/path/ user@remote:/target/path

Modified working version:

rsync -rlptDz --links -O /source/path/ user@remote:/target/path

Breaking down the flags:

  • -r: recursive
  • -l: copy symlinks as symlinks
  • -p: preserve permissions (we'll address this below)
  • -t: preserve modification times
  • -D: preserve devices and special files
  • -z: compress during transfer

For more granular control, consider these additional approaches:

1. Completely skip permission changes:

rsync -rlptDz --no-perms --links -O /source/path/ user@remote:/target/path

2. Only preserve specific attributes:

rsync -rltDz --links -O /source/path/ user@remote:/target/path

Note the removed -p flag to skip permission preservation entirely.

When dealing with different permission-related issues:

Case 1: Preserving ownership (requires root)

rsync -avz --no-perms --links -O --rsync-path="sudo rsync" /source/ user@remote:/target/

Case 2: Working with restricted directories

rsync -rltDz --links -O --chmod=ugo=rwX /source/ user@remote:/target/

For repeated use, consider adding these to your ~/.rsync-filter file:

-p
--no-perms

Or create an alias in your shell configuration:

alias rsyncsafe='rsync -rltDz --no-perms --links -O'