Automatically force all files in a directory to have the same UID/GID?
Linux - GeneralThis Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Automatically force all files in a directory to have the same UID/GID?
Hi all,
This is a simple question, and it may have a simple answer or maybe no answer at all...
Is there a simple way to setup a directory so that any file moved, copied or created in it will always have the same UID?
The idea here would be that say a home user's folder is configured so that anything placed there always has the correct UID.
So even if root copied a folder from anywhere on the system to that user's home folder, the copy's UID/GID would automatically be set to that of the given user.
The application for this is a custom built NAS server. I only care about share-level security; I basically allow or disallow users to access shares via SMB and use the force user directive in smb.conf to force the uid for access to given folders as desired. This means that I can have several user accounts login that all have full read-write access to the same share without complicated "I created that file but now you can't modify it" issues.
The problem arises if I want to move or copy a large folder manually. If I have, say, a 10GB work folder that needs to move from one share to another, I'll execute an mv on the server, rather than copying it at a workstation. This is because the server can then just move the folder, rather than copying the file back and forth over the network. If I forget to chown the folder after moving it, though, this creates a problem.
I currently have a script set to run every few hours via cron that scans all the NAS folders using the find command, looking for files that don't match the correct UID/GID and executing chown per file. But short of doing this, which seems a bit disk-intensive given the task at hand, is there a more efficient way to do this?
Oh, no, I understand doing chown -R. I am currently doing that when I copy something, and I also have a script performing chown -R on the entire folder periodically using find to determine which files to change.
What I was looking for was something automatic - like a way to configure the filesystem such so that any file copied to a certain folder automatically gets its UID/GID altered.
Imagine when you mount a FAT filesystem on some location and you can use mount options to force its UID/GID to remain constant.
I'm wondering if something similar to Tripwire might be able to do this? Monitor a given directory and, whenever a file is placed there, perform the chown?
However, the normal system is to designate an owning group and set 'chmod g+s' on the dir.
This causes all files created in/copied to that dir to have the same gid as the enclosing dir.
Just add all users to that group and don't worry about uid; you don't need that set.
In fact, normally you'd create a dedicated acct to own that, and only give the passwd to the group/project owner (or admin).
This is less load than inotify etc and doesn't require 1 or more processes to always(!) be running.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.