My solution is to use --rsync-path="sudo rsync", if it ask for password you can use workaround like this:
rsync -avz --stats --rsync-path="echo <SUDOPASS> | sudo -Sv && sudo rsync" user@192.168.1.2:/ .
However, it is better to not type your password on the commandline, where it sill be stored in terminal history. Instead, you can use read -s to prompt for the password without showing it:
read -s -p "Remote sudo password: " SUDOPASS && rsync -avz --stats --rsync-path="echo $SUDOPASS | sudo -Sv && sudo rsync" user@192.168.1.2:/ .
(Note: -p to prompt isn't supported in all shells (e.g. zsh), if you get an error you can leave it off, or echo before reading instead)
-e="ssh -i $PRIVATE_KEY_PATH" --rsync-path="sudo rsync"– A T May 15 '17 at 06:01/etc/sudoerscomes at the end of the file (or after any group rules which may affect the same user) solved the problem for me. – CPBL Jan 28 '19 at 01:15<username> ALL=NOPASSWD:<path to rsync> <args>but I don't know what the args would be when called remotely like this. Any ideas? – Pete Cornell Sep 12 '19 at 01:00Defaults requirettySSHD configuration on the remote side. – TrinitronX Jun 08 '20 at 21:31alias rsync-sudo='rsync --rsync-path="sudo rsync"'– kenorb Aug 03 '21 at 09:02sudoers. I set<username> ALL=(ALL)NOPASSWD: /usr/bin/rsyncin/etc/sudoers.d/usernameand expected that is would do the job. Turned out in my/etc/sudoersthere was a%some-usergroup ALL=(ALL) ALLline (username is a member of that some-usergroup) after@includedir /etc/sudoers.d. Moving the%some-usergroup <..>line before@includedirfixed my remotesudo rsyncproblems. – DmitrySandalov Sep 15 '22 at 07:10