Rsync using sudo over SSH


If you can ssh to a remote server using your public key, but want rsync to be executed as a different user, you can achieve it like this:

On the remote host add an entry in /etc/sudoers which looks like this (replace the username accordingly):
user1    ALL=NOPASSWD: /usr/bin/rsync *
This will allow your user account user1 to run rsync commands via sudo once he's logged in.

Then run rsync like this (change paths accordingly):
rsync -a -e "ssh" –rsync-path="sudo rsync" user1@server.example.net:/source/folder/ /destination/folder/