1

I would like to use rsync via ssh to copy files from source-machine to dest-machine (both Linux boxes). Due to a security policy that is beyond my control, the files on dest-machine must be owned by user1 but user1 is not allowed to log in. I am user2 and can log in via ssh to both machines, user2 is in the same group as user1, and both users exist on both machines. After logging into either machine user1 can become user2 by first doing sudo -s (no password prompt) and then su user1.

The files typically have the following permissions:

source-machine:
-rw-rw-r-- user2  group1  file.txt

dest-machine:
-rw-rw-r-- user1  group1  file.txt

Rsync always changes the ownership on dest-machine to be user2, becuase I am using

/usr/bin/rsync -rlvx --delete --exclude-from ignore-file.txt --rysnc-path="/usr/bin/rsync" /path/to/files/ -e ssh user2@dest-machine.example.com:/path/to/files/

as part of the rsync command. At the moment, I have to work out which files have been copied and change the ownership back to user1.

I saw in this discussion that it may be possible to use

--rsync-path='sudo -u user2 rsync'

but I need the intermediate step of sudo -s.

Is there a way to get rsync to leave the files on dest-machine owned by user1?

UPDATE: Thanks to mnagel's comment, I tried that permutation, and when that didn't work, I was exploring why and added two more permutations: (1) I ran the script at source-machine as root and (2) I had somehow not included -go as options. (I hadn;t used -a, as the security policy doesn't allow preserving times). When put altogether, it works.

4

0 回答 0