Syncing local and remote directories using rsync+ssh+public key as a user different to the ssh key owner Syncing local and remote directories using rsync+ssh+public key as a user different to the ssh key owner unix unix

Syncing local and remote directories using rsync+ssh+public key as a user different to the ssh key owner


I have not tried it by myself, but how about using rsync's '--rsync-path' option?

rsync -rtvz --rsync-path='sudo -u user2 rsync' /path/to/local/folder server1:/path/to/remote/folder


To fix the permissions problem you need to run rsync over an an SSH session that logs in remotely as user2:

rsync avz -e 'ssh -i privatekeyfile' /path/to/local/folder/ user2@server1:/path/to/local/folder

The following answer explains how to setup the SSH keys.


Set up password-less access for user1 to access user2@server1, then do:

rsync -rtvz /path/to/local/folder user2@server1:/path/to/remote/folder