LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This 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


Reply
  Search this Thread
Old 04-22-2013, 09:01 PM   #1
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Rep: Reputation: 27
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?

F
 
Old 04-22-2013, 09:10 PM   #2
John VV
LQ Muse
 
Registered: Aug 2005
Location: A2 area Mi.
Posts: 17,627

Rep: Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651Reputation: 2651
see the help and man page for chown

Code:
su -
chown -R user:group FolderName
and for "cp" and "mv"

Last edited by John VV; 04-22-2013 at 09:16 PM.
 
Old 04-22-2013, 11:36 PM   #3
fmillion
Member
 
Registered: Nov 2006
Posts: 93

Original Poster
Rep: Reputation: 27
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?

F
 
Old 04-23-2013, 03:56 AM   #4
chrism01
LQ Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,360

Rep: Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751Reputation: 2751
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.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
NFS - files/directories created with local UID/GID muis87 Linux - Networking 4 04-02-2012 01:25 AM
what is uid and gid rmanocha Linux - Software 9 08-18-2008 11:03 PM
Default UID / GID / Security Context for httpd root directory rioguia Linux - Security 1 05-09-2006 12:26 PM
What is my uid/gid? Jeebizz Slackware 2 11-22-2005 11:39 AM
uid, gid don't exist, yet files owned by them, i need to delete them mattie_linux Linux - General 10 05-05-2005 03:57 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

All times are GMT -5. The time now is 02:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration