88

I have an sshfs connection setup with a remote filesystem on a Linux server. I'm doing an rsync from my local server to the ftpfs-filesystem. Because of the nature of this setup, I can't chown anything on the sshfs filesystem.

When I do the rsync, it tries to chown all the files after it transfers them. This results in chown errors, even though it transfers the files just fine.

With rsync, is there a way to tell it to not try and chown the files? If I rsync like 1000 files I end up with a log of 1000 chown: permission denied (error 13) errors. I know it doesn't hurt anything to get these errors since the ownership of the files is determined by the sshfs configuration itself, but it would be nice to not get them.

4 Answers 4

128

You are probably running rsync like this:

rsync -a dir/ remote:/dir/

The -a option according to the documentation is equivalent to: -rlptgoD

      -a, --archive    archive mode; equals -rlptgoD (no -H,-A,-X)

You probably want to remove the -o and -g options:

      -o, --owner                 preserve owner (super-user only)
      -g, --group                 preserve group

So instead your rsync command should look something like this:

rsync -rlptD dir/ remote:/dir/

Or as @glglgl points out:

rsync -a --no-o --no-g dir/ remote:/dir/

The remaining options in use are:

      -r, --recursive             recurse into directories
      -l, --links                 copy symlinks as symlinks
      -p, --perms                 preserve permissions
      -t, --times                 preserve modification times
      -D                          same as --devices --specials
          --devices               preserve device files (super-user only)
          --specials              preserve special files
4
  • 26
    ... or just -a --no-o --no-g
    – glglgl
    Feb 29, 2012 at 7:43
  • 1
    I used just rsync -r --no-o --no-g /source/* /dest/ and my owner and group of the files at the destination were still changed according to the source. Any ideas?
    – Ram Patra
    Sep 18, 2017 at 21:35
  • ... or just -a --chown=whomever:whomever so you're explicitly setting the destination's owner and group to whomever you want them to be.
    – Bob Stein
    Apr 1, 2021 at 19:20
  • Unfortunately with the rsync daemon this isnt possible, as all we can do is refuse options. And from the man page, should we refuse a chown (or in my case wanting --no-o --no-g), we face "When an option is refused, the daemon prints an error message and exits." which would kill the transfer.
    – math
    Jan 8, 2023 at 15:28
12

Don't pass -o or any of the other options that implies it.

5

Don't use the -a option, as it will include the -p option that keeps the permissions. For this situation, the -r should be enough.

For more infos, see man rsync.

2
  • 5
    Are you sure -p is what I want to avoid? Ownership is different than permissions, correct? Feb 29, 2012 at 16:04
  • I use -rlt on upload so ownership and permissions aren't uploaded, but timestamps and links are uploaded.
    – Bob Stein
    Aug 11, 2021 at 14:47
0

I encountered something similar whereby rsync was not retaining the owner and group of files & directories been synced from a remote server. To correct, I copied over the /etc/shadow, /etc/group and /etc/passwd files.

When I ran the rsync command below it then worked in that it retained permissions, symbolic links & ownership.

I had set up ssh keys to use passwordless ssh.

rsync -avpog [email protected]:/usr/local /usr

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .