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)