Score:1

Rsync makes the destination folder unwritable before copying files to it (and then of course it fails with Permission Denied)

in flag

I want to use rsync to deploy a project from my dev machine (Windows 11, CygWin) to a remote server (Ubuntu) through SSH. I've made sure that my SSH user has full write access to the destination folder by running the commands below:

root# mkdir /opt/my-project
root# chmod +rwx /opt/my-project
root# cwown -R ubuntu /opt/my-project
ubuntu$ touch /opt/my-project/test && rm /opt/my-project   # No errors

On my Windows machine, I am using the following rsync command:

C:\cygwin64\bin\rsync.exe -Pav \
    -e "C:/cygwin64/bin/ssh.exe -i <SSH Key File>" \
    ./bin/Release/net6.0/linux-x64/publish/ ubuntu@my_server:/opt/my-project/

I would expect this command to start an incremental file synchronization, and upload all the missing files to the project folder on the server. But instead, the rsync tool spits out a bunch of Permission denied (13) errors and fails to copy a single file. On top of that, when I go back to the server to check the target folder, the ubuntu user no longer has any form of access to it. Even listing the folder (ls /opt/my-project) gives a Permission denied error.

This is a very strange behavior, because prior to the upload, the ubuntu user definitely has full write access to the target folder, but it seems like rsync intentionally locks itself out of the folder before transferring a single file.

Here's the shortened output of the rsync command:

sending incremental file list
rsync: failed to modify permissions on "/opt/my-project/.": Permission denied (13)
rsync: recv_generator: failed to stat "/opt/my-project/file1.so": Permission denied (13)
rsync: recv_generator: failed to stat "/opt/my-project/file2.so": Permission denied (13)
...
rsync: recv_generator: mkdir "/opt/my-project/file420.so" failed: Permission denied (13)
*** Skipping any contents from this failed directory ***
...
sent 71,147 bytes  received 53,278 bytes  49,770.00 bytes/sec
total size is 314,634,345  speedup is 2,528.71
rsync error: some files/attrs were not transferred (see previous errors) (code 23) at main.c(1330) [sender=3.2.4dev]

What's causing this behavior?

Rsync and OS versions:

  • Local: Windows 11, CygWin/rsync version 3.2.4dev protocol version 31
  • Remote: Ubuntu 20.04, rsync version 3.1.3 protocol version 31
Score:1
in flag

For some reason the default rsync that comes with CygWin doesn't seem to be compatible with remote Linux filesystems. The solution was to install rsync from here: https://github.com/Bill-Stewart/CygSSH

By using this, everything works as expected.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.