Score:0

Fix permissions on files copied to samba shares automatically

ye flag

so I have a samba share where I have multiple groups and user. in my case:

A user named CEO would be a member of groups Partners and Users,

While user Clerk would be just a member of group Users .

There are 2 Shared folders, Common, and Partners-only. Common would be owned by users and Partners-only by Partners. So the CEO can Access both Common and Partners-Only, while Clerk can only Access Common.

Now the issue is that when CEO copies something from Partners-Only onto Common, the permission stay that the file is owned by Partners group and any regular user cannot access the file.

I have a fix for it with crontab that goes like this:

*/5 * * * * /usr/bin/chgrp  -R Users /mnt/Common/ >> /var/log/permissions/Common.log 2>&1
*/5 * * * * /usr/bin/chmod  -R g+rw /mnt/Common >> /var/log/permissions/partners.log 2>&1

And it works, however, the issue is that with many different groups and shares I have simular cronjob too many times and it puts too much strain on the server.

Is there a way to get samba to adjust permissions on its own when a file is copied? thanks

David avatar
cn flag
What version of Ubuntu? What file system type for all the partitions involved?
Marc Vanhoomissen avatar
in flag
Did you consider using directives `force user` and `force group` in your settings? Could you post the relevant parts of your `smb.conf` file?
Score:1
es flag

How about something like this ... assuming I have a folder at /mnt/Common:

Change ownership and apply the setgid bit to that folder:

sudo chown :users /mnt/Common
sudo chmod 2775 /mnt/Common

The setgid bit will force every new file added on the server itself to this directory to inherit the group of the parent.

Then create a share definition in smb.conf that looks something like this:

[Common]
path = /mnt/Common
valid users = @users @partners
force group = users
writeable = yes
create mask = 0664
force directory mode = 2775

When a member of either group adds a file to the share it will save with group = users and permissions of 664. Any new subdirectory added will save with group = users, set folder permissions to 775, and will apply the setgid bit to that subdirectory.

mangohost

Post an answer

Most people don’t grasp that asking a lot of questions unlocks learning and improves interpersonal bonding. In Alison’s studies, for example, though people could accurately recall how many questions had been asked in their conversations, they didn’t intuit the link between questions and liking. Across four studies, in which participants were engaged in conversations themselves or read transcripts of others’ conversations, people tended not to realize that question asking would influence—or had influenced—the level of amity between the conversationalists.