How to write to remote side with sudo in rsync?

Here is the case, the user can not write directly to the remote sideā€™s directory, while the user can sudo on the remote side and write the directory with sudo.

How to write to remote side with sudo in rsync?

On the source machine, run the rsync command with

--rsync-path="sudo rsync"

added. For example,

rsync -avxP --rsync-path="sudo rsync" /local/path/ user@remote:/remote/path/

Here, --rsync-path specifies the command to run on the remote machine.

Note that this work only if the user on the remote machine can do sudo without password. To set up password-less sudo, on the remote side,

sudo visudo

and add a line like this


where, USER is the user name and PATH_TO_RSYNC should be the path of the rsync on the remote machine (you can find it out by which rsync).

Eric Ma

Eric is a systems guy. Eric is interested in building high-performance and scalable distributed systems and related technologies. The views or opinions expressed here are solely Eric's own and do not necessarily represent those of any third parties.

Leave a Reply

Your email address will not be published. Required fields are marked *