Using Sudo With Rsync

So today I was presented with a problem. I needed to get a set of files copied from one machine to another with their permissions intact, but the were owned by root. I reached for my trusty rsync, and realized I didn’t have a way to set root perms on the remote machine.

We don’t allow root ssh into any of our machines, for obvious reasons, so I was stuck. After a rather lengthy google search, I pieced enough information together to figure out that I could use an argument to rsync to set the program I wanted to use as rsync on the remote machine. This is typically used when the remote machine doesn’t have rsync installed system wide, but in a user account, etc.

By telling rsync that the —rsync-path=“sudo rsync”, I could run rsync on the remote machine as root, and copy my files, complete with root perms! My user account has passwordless sudo access so this just worked for me, but if you need to, you could probably ssh into the remote machine and “sudo ls” to get a password prompt, to ‘prime’ the sudo mechanism.

Hope this helps!

/korishev

Comments