Automatically force all files in a directory to have the same UID/GID?
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?
see the help and man page for chown
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?
Try inotify http://linux.die.net/man/7/inotify, inotifywait http://linux.die.net/man/1/inotifywait.
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.
|All times are GMT -5. The time now is 08:43 AM.|