rsync - mkstemp failed: Permission denied (13)

153,269

Solution 1

Make sure the user you're rsync'd into on the remote machine has write access to the contents of the folder AND the folder itself, as rsync tried to update the modification time on the folder itself.

Solution 2

Even though you got this working, I recently had a similar encounter and no SO or Google searching was of any help as they all dealt with basic permission issues wheres the solution below is somewhat of an off setting that you wouldn't even think to check in most situations.

One thing to check for with permission denied that I recently found having issues with rsync myself where permissions were exactly the same on both servers including the owner and group but rsync transfers worked one way on one server but not the other way.

It turned out the server with problems that I was getting permission denied from had SELinux enabled which in turn overrides POSIX permissions on files/folders. So even though the folder in question could have been 777 with root running, the command SELinux was enabled and would in turn overwrite those permissions which produced a "permission denied"-error from rsync.

You can run the command getenforce to see if SELinux is enabled on the machine.

In my situation I ended up just disabling SELINUX completely because it wasn't needed and already disabled on the server that was working fine and just caused problems being enabled. To disable, open /etc/selinux/config and set SELINUX=disabled. To temporarily disable you can run the command setenforce 0 which will set SELinux into a permissive state rather then enforcing state which causes it to print warnings instead of enforcing.

Solution 3

Rsync daemon by default uses nobody/nogroup for all modules if it is running under root user. So you either need to define params uid and gid to the user you want, or set them to root/root.

Solution 4

I encountered the same problem and solved it by chown the user of the destination folder. The current user does not have the permission to read, write and execute the destination folder files. Try adding the permission by chmod a+rwx <folder/file name>.

Solution 5

This might not suit everyone since it does not preserve the original file permissions but in my case it was not important and it solved the problem for me. rsync has an option --chmod:

--chmod This option tells rsync to apply one or more comma-separated lqchmodrq strings to the permission of the files in the transfer. The resulting value is treated as though it was the permissions that the sending side supplied for the file, which means that this option can seem to have no effect on existing files if --perms is not enabled.

This forces the permissions to be what you want on all files/directories. For example:

rsync -av --chmod=Du+rwx SRC DST

would add Read, Write and Execute for the user to all transferred directories.

Share:
153,269
Admin
Author by

Admin

Updated on July 05, 2022

Comments

  • Admin
    Admin almost 2 years

    I have the following setup to periodically rsync files from server A to server B. Server B has the rsync daemon running with the following configuration:

    read only = false
    use chroot = false
    max connections = 4
    syslog facility = local5
    log file = /var/adm/rsyncd.log
    munge symlinks = false
    secrets file = /etc/rsyncd.secrets
    numeric ids = false
    transfer logging = true
    log format = %h %o %f %l %b
    
    
    [BACKUP]
            path = /path/to/archive
            auth users = someuser
    

    From server A I am issuing the following command:

    rsync -adzPvO --delete --password-file=/path/to/pwd/file/pwd.dat /dir/to/be/backedup/ [email protected]::BACKUP
    

    BACKUP directory is fully read/write/execute to everyone. When I run the rsync command from server A, I see:

    afile.txt
             989 100%    2.60kB/s    0:00:00 (xfer#78, to-check=0/79)
    

    for each and everyfile in the directory I wish to backup. It fails when I get to writing tmp files:

    rsync: mkstemp "/.afile.txt.PZQvTe" (in BACKUP) failed: Permission denied (13)
    

    Hours of googling later and I still can't resolve what seems to be a very simple permission issue. Advice? Thanks in advance.

    Additional Information

    I just noticed the following occurs at the beginning of the process:

    rsync: failed to set permissions on "/." (in BACKUP): Permission denied (13)
    

    Is it trying to set permission on "/"?

    Edit

    I am logged in as the user - someuser. My destination directory has full read/write/execute permission for everyone, including it's contents. In addition, the destination directory is owned by someuser and in someuser's group.

    Follow up

    I've found using SSH solves this

  • Admin
    Admin almost 12 years
    Thank you for your reply. I've ensured I am the same user with permission, ownership and group settings. Please see my edit.
  • GTodorov
    GTodorov about 8 years
    Genius! Thank you for this great tool!
  • user10607
    user10607 over 7 years
    This answer really helped me. I had to set up the rsync daemon since rsync over ssh was too slow (plus I would have to allow root over ssh, which is no good). But I kept getting failed to set times on "/." (in linuxbackup): Operation not permitted (1) even though the remote daemon was already running as root. Changing uid and gid to root in rsyncd.conf fixed that
  • Gahan
    Gahan almost 7 years
    it's better to write example also.
  • Simon
    Simon almost 7 years
    Same for me backuping a Synology NAS to a distant server using rsync over SSH.
  • Christian Ulbrich
    Christian Ulbrich about 6 years
    For me it was SELinux! Thanks!
  • fdelia
    fdelia about 6 years
    Synology-NAS: I had to add --rsync-path=/bin/rsync to rsync to get rid of the "permission denied".
  • M46
    M46 about 4 years
    Thanks. I had this problem on a Synology DiskStation and it solved the problem. It is irrelevant if the owner is an administrator or not, the folder must be owned by the rsync job user.
  • Paul Podgorsek
    Paul Podgorsek about 4 years
    Thanks so much, you finally unblocked my installation of rsync! I totally agree with you, SELinux exists for a reason, it's a pity so many people just disable it instead of learning how it works.
  • CodeMouse92
    CodeMouse92 almost 4 years
    "sudo" is not a fix unless you know for certain what the problem is. More often then not, blindly sudoing will cause more problems than it fixes.
  • Marecky
    Marecky over 3 years
    If I get "command not found" for getenforce does this mean that my server does not have SELinux?
  • Jeff Wilbert
    Jeff Wilbert over 3 years
    @Marecky Not necessarily, depending how you are running the command and/or how your $PATH variable is setup could result in command not found. Try running /usr/sbin/getenforce which is the full path where getenforce usually is.
  • Jeff Wilbert
    Jeff Wilbert over 3 years
    @Marecky You can also do a search of the installed packages yum list installed | grep selinux or apt list --installed | grep selinux depending on distro. Note that if libselinux is found that doesn't mean it's enabled and/or active on the server. Another alternative to selinux to check for is AppArmor apparmor_status.
  • Altimac
    Altimac over 3 years
    it's apparently important to own the entire path hierarchy. Being the owner of the destination folder is not enough. You have to own the parent directories too. I'm a bit suprised but it worked only if I'm the owner of all parents....
  • Jakob Ojvind Nielsen
    Jakob Ojvind Nielsen over 2 years
    As @fdelia suggesting adding --rsync-path=/usr/bin/rsync to the rsync command I now have rsync -rvp --rsync-path=/usr/bin/rsync $SOURCE $DESTINATION solved my problem magically. But I don't know why and thats a bit frustrating.
  • Ramon Fincken
    Ramon Fincken almost 2 years
    Indeed, thanks @mauvis-ledford , in this case the remote folder was root:root instead of someuser:someuser ( and we connected using someuser ... )