Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to rsync and preserve owner of files at destination
    primarykey
    data
    text
    <p>I would like to use rsync via ssh to copy files from <em>source-machine</em> to <em>dest-machine</em> (both Linux boxes). Due to a security policy that is beyond my control, the files on <em>dest-machine</em> must be owned by <em>user1</em> but <em>user1</em> is not allowed to log in. I am <em>user2</em> and can log in via ssh to both machines, <em>user2</em> is in the same group as <em>user1</em>, and both users exist on both machines. After logging into either machine <em>user1</em> can become <em>user2</em> by first doing <em>sudo -s</em> (no password prompt) and then <em>su user1</em>.</p> <p>The files typically have the following permissions:</p> <pre><code>source-machine: -rw-rw-r-- user2 group1 file.txt dest-machine: -rw-rw-r-- user1 group1 file.txt </code></pre> <p>Rsync always changes the ownership on <em>dest-machine</em> to be user2, becuase I am using</p> <pre><code>/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/ </code></pre> <p>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 <em>user1</em>.</p> <p>I saw in <a href="https://stackoverflow.com/questions/14351190/syncing-local-and-remote-directories-using-rsyncsshpublic-key-as-a-user-differ">this discussion</a> that it may be possible to use</p> <pre><code>--rsync-path='sudo -u user2 rsync' </code></pre> <p>but I need the intermediate step of <em>sudo -s</em>.</p> <p>Is there a way to get rsync to leave the files on <em>dest-machine</em> owned by <em>user1</em>?</p> <p>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 <em>source-machine</em> 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. </p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload