Is there a way to specify destination permissions with rsync?

Red Squirrel

No Lifer
May 24, 2003
69,691
13,325
126
www.betteroff.ca
I googled this and I can only find how to preserve the permissions, but not how to actually set them.

Here's my situation, I have my main server which has a samba share and I code off of that. The code is actually tested on a separate server. Rather then make another separate samba share off that server I rather keep everything central. The problem is, when I rsync the code over to the server, it just goes as whatever permissions it wants. Typically, root. I can preserve permissions, but it's just going to end up being random based on whatever that uid and guid happens to be on that server.

My script just does a chown -R and chmod -R to fix the permissions but this just seems dirty, because it has to run through every single file each time.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
It doesn't choose whatever permissions it wants, it uses the user id that ssh logs in as and the configured umask to determine the permissions. Just like every other console app in Linux. If you can't fix the login and umask used by rsync to preserve the permissions appropriately, fixing them with chmod/chown is the only other way.
 

Red Squirrel

No Lifer
May 24, 2003
69,691
13,325
126
www.betteroff.ca
So there's no flag to just specify a user/group? The permissions I want are apache (the code is a web app), unless I give that shell access and rsync with that... Given that's a system user not sure if that would even be possible.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
So there's no flag to just specify a user/group? The permissions I want are apache (the code is a web app), unless I give that shell access and rsync with that... Given that's a system user not sure if that would even be possible.

You have access to the same man page that I do, do you see such an option?

It's definitely possible, there's no real difference between system accounts and user accounts. But that means you would need to make sure it has an extremely secure password or none at all and just use ssh key authentication.
 

Red Squirrel

No Lifer
May 24, 2003
69,691
13,325
126
www.betteroff.ca
I checked the man page and don't see any option, but figured maybe there could possibly be an undocumented way or something. Guess I'll just stick with the script that resets all the permissions. I just wish Linux permissions would be as simple as they are in Windows. You set it on the root folder, and everything traverses unless you change it.
 

LCTSI

Member
Aug 17, 2010
93
0
66
I checked the man page and don't see any option, but figured maybe there could possibly be an undocumented way or something. Guess I'll just stick with the script that resets all the permissions. I just wish Linux permissions would be as simple as they are in Windows. You set it on the root folder, and everything traverses unless you change it.

if you disable --perms it will keep whatever bits were already set on the destination, but you can use an additional arg to specify bits to apply against the dest umask.

(--perms section of the manual)


You probably don't need to run rsync as root here, just run it as a user in the same group as the application user (what server, apache?) and make sure the group has access to the files. Then you can specify --no-owner and --no-group and it will set to the umask of the rsync user + the bits you set.
 

Nothinman

Elite Member
Sep 14, 2001
30,672
0
0
I checked the man page and don't see any option, but figured maybe there could possibly be an undocumented way or something. Guess I'll just stick with the script that resets all the permissions. I just wish Linux permissions would be as simple as they are in Windows. You set it on the root folder, and everything traverses unless you change it.

NTFS ACLs are way more complicated than they need to be 99% of the time and most people don't understand them properly anyway. Inheritance is nice in some cases, but being able to easily see who has what access to a file without requiring an "effective permissions" tool is a huge benefit from the simplicity of Linux permissions.
 

LCTSI

Member
Aug 17, 2010
93
0
66
Also if you are repeatedly testing the code on another server you might look at Capistrano and/or Webistrano to deploy that from git.