I have one local server, let's call it as A, which has access to a remote server.

I want to synchronize with rsync a directory from the remote server to the local one, and I want to put the synchronized directory in a mounted unit on A.

The problem is that the remote directory has restricted permissions, so I must run the rsync command in sudo mode on the remote server, but from the server A.

How can I do?


The strategy more simple is to log in the remoteserver and from there run the rsync command, with sudo privileges.

I assume you are working under Linux on both machines.
Let's we call localuser the username on the localserver, and remoteuser the username on the remoteserver.

  • On the localserver is mounted an external unit in the path /media/MyUsb
  • On the remoteserver there is a directory called /data/DirToSync.
localuser@localserver ~> ssh -X remoteuser@remoteserver

It should ask you the password for the remoteuser on the remoteserver and after it will show the prompt on the remote server:

remoteuser@remoteserver -> 

Here you can write the rsync command:

sudo rsync  -av /data/DirToSync localuser@localserver:/media/MyUsb

It will ask before the password for sudo on the remote machine (the one of remoteuser@remoteserver) and after the password of the destination(the one of localuser@localserver).


  1. You need to be in the sudoers list of the remote machine (it means you have to have the right to run sudo). Try to do sudo ls on the remote server and give your password when requested. If it will execute the ls command you are in that list. (It should be a really rare and insecure case if you were in that list and with no need of password; in that case you have not to write the password for sudo).
  2. It will be not asked you the passwords for the ssh/rsync connections if you have generated and installed the ssh-keys.
  3. via ssh you can even send the sudo command to rsync from there to the localhost, but it is a little more complex syntax, see here for example, and you can incur in some problem because of sudo on some version of linux.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.