@lexi.ch home, code, stuff

Rsync a remote machine without root login 23.03.2014

The problem: you want to full-rsync a remote machine, but you can only log in using an unprivileged (non-root) user.
The solution: sudo with the correct setup does the trick!

1. prerequisites

2. Configure sudo on the remote machine

On the remote machine, we can login with the user backupuser, but this is an unprivileged user. We want this user to become root passwordless, but only for the rsync command.

We configure sudo so that the backupuser can use rsync, and rsync only, passwordless as root:

> sudo visudo

## add the following line, changing the username as apropriate:
remotebackup  ALL=NOPASSWD:/usr/bin/rsync

This enables the user backupuser to become root passwordless, but only for the rsync command.

3. Invoking rsync on the local machine with --rsync-path

Now you can use rsync on the local machine to fetch the parts you want to copy. Make sure you set the --rsync-path option:

> rsync -av --rsync-path="sudo rsync" backupuser@remotehost:/remote/path/ /local/backup/path/