LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-10-2010, 05:29 AM   #1
TheLudd
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Rep: Reputation: 0
Default group owner of files in a directory?


Hello!
I have recently installed ubuntu server on a new machine. I have added 3 users and I have assigned them to a group.

The three of us work together on a lot of stuff so what I would like to do is to have a specific folder made the groups folder. All files that are created or moved into this folder should automatically be owned by the group. I.e. all 3 of us should have the right to read and write to these files.

Is that possible?
 
Old 09-10-2010, 05:43 AM   #2
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
Lightbulb

You can use the below commands

Code:
chgrp groupname /your/folder
or if you want to use ACL (Access Control List).

Code:
setfacl -m g:groupname:7 /your/folder
 
Old 09-10-2010, 05:45 AM   #3
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
You can check for setgid. Though this has to be done manually.
 
Old 09-10-2010, 05:54 AM   #4
TheLudd
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Yes, with chgrp I can change the owner of the folder, but the problem remains:

When new files are added, they belong to the adding user, not the group.
When the other users add a file, I can not edit it. I want this to be possible.
 
Old 09-10-2010, 06:45 AM   #5
linuxlover.chaitanya
Senior Member
 
Registered: Apr 2008
Location: Nagpur, India
Distribution: Cent OS 5/6, Ubuntu Server 10.04
Posts: 4,629

Rep: Reputation: Disabled
If you are using chgrp command for the solution, use -R option to make it recursive. Else look into the link in my post#3
 
Old 09-10-2010, 07:22 AM   #6
vikas027
Senior Member
 
Registered: May 2007
Location: Sydney
Distribution: RHEL, CentOS, Debian, OS X
Posts: 1,298

Rep: Reputation: 102Reputation: 102
You can also use ACL as suggested by me in post#2
 
Old 09-10-2010, 08:21 PM   #7
gdejonge
Member
 
Registered: Aug 2010
Location: Netherlands
Distribution: Kubuntu, Debian, Suse, Slackware
Posts: 317

Rep: Reputation: 73
What you need is setting a special status bit on the directory.

First do a change group at the directory itself. Like:
Code:
chgrp -R staff <directory>

After that you need to change the mode of the directory like
Code:
chmod 2775 <directory>
After this do a ls -l of the directory
it should show something like this:
Code:
drwxrwsr-x 2 gerrard video 4096 2010-09-11 03:10 test
Notice the bold character.
This tells the system to preserve the group id of the directory on newly created files inside the directory.

_____________________
Gerrard
 
Old 09-11-2010, 02:11 AM   #8
TheLudd
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by gdejonge View Post
What you need is setting a special status bit on the directory.

First do a change group at the directory itself. Like:
Code:
chgrp -R staff <directory>

After that you need to change the mode of the directory like
Code:
chmod 2775 <directory>
After this do a ls -l of the directory
it should show something like this:
Code:
drwxrwsr-x 2 gerrard video 4096 2010-09-11 03:10 test
Notice the bold character.
This tells the system to preserve the group id of the directory on newly created files inside the directory.

_____________________
Gerrard
I get the same result as you, but its still not working properly.
I create the directory, cd into it and create a file using touch.
When doing ls- l I get this:
Code:
-rw-r--r-- 1 [creating_user] mygroup    0 2010-09-11 08:56 test_file.txt
Other users in still can't edit the new file. Did I miss something?
 
Old 09-11-2010, 02:17 AM   #9
TheLudd
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by linuxlover.chaitanya View Post
You can check for setgid. Though this has to be done manually.
I used the example found here http://en.wikipedia.org/wiki/Setuid#...on_directories

And it kind of half-works...
I cannot edit a file and replace the contents in it, but I can remove it and replace it with my new edited file.
 
Old 09-11-2010, 02:51 AM   #10
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,608

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Hi,

you could try changing your umask flags to '002' so that files will be created with default permission 0664. However, this will create all your files with this permissions even the ones you do not want to share with other group members.

Another possibility is to have a closer look at ACL, as already has been suggested. I am not very familiar with ACL.

If this still does satisfy your purpose then you could have a look at incrond. This is a demon that you can configure to monitor a directory and have it execute certain actions, e.g. on file creation. In your case this would be to change the permission settings.
http://linux.die.net/man/8/incrond
http://linux.die.net/man/5/incrontab
http://linux.die.net/man/5/incron.conf
 
Old 09-11-2010, 03:06 AM   #11
TheLudd
LQ Newbie
 
Registered: Sep 2010
Posts: 12

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by crts View Post
you could try changing your umask flags to '002' so that files will be created with default permission 0664.
I'm sorry. As a beginner I do not understand the meaning of this. Could you demonstrate with an example?

And yes, I DO want all the files to be editable by everyone. This is for a specific directory. Users can still have their own files elsewhere. This is for a directory where we are collaborating.
 
Old 09-11-2010, 03:27 AM   #12
crts
Senior Member
 
Registered: Jan 2010
Posts: 1,608

Rep: Reputation: 449Reputation: 449Reputation: 449Reputation: 449Reputation: 449
Quote:
Originally Posted by TheLudd View Post
I'm sorry. As a beginner I do not understand the meaning of this.
Ok,

then you probably don't want umask. It would cause other issues that you would have to deal with. So just forget about umask.

You should check out the links for incrond I provided. Create a group, lets call it 'staff', and a directory /home/common. Add every user you want to share files in /home/common to 'staff'. change group and permissions of /home/common
Code:
sudo chgrp staff /home/common
chmod 0770 /home/common
Next install and configure incrond to monitor /home/common. Upon file creation in that directory have the demon change the group and permission of the newly created file. Post again if you have trouble configuring incrond.
 
Old 08-14-2014, 04:41 AM   #13
AKwonder
LQ Newbie
 
Registered: Aug 2014
Posts: 1

Rep: Reputation: Disabled
If you change your default group to the same group that all three people are in, then the group will have access to all newly created files. Using the usermod or useradd command, there is a -g and -G argument that can be used. The -g argument will allow you to specify the default group that will take ownership of newly created files. You want this default group to match the group of your three members. The other option is to change the group ownership of a file after you create it using the chgrp command, but I'm guessing you would want to use the former. If you use ls -l, you can see what group the file being created is owned by, and what is currently set as your default group.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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 Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Owner 99 Group 99 files & folders adnanm Linux - Newbie 1 05-26-2008 11:02 AM
Files getting created with owner as nobody and group as nogroup, how to stop? itsakc Linux - General 2 10-25-2007 06:13 PM
Broken files/owner/group. kmoffat Debian 3 11-27-2006 07:18 PM
sudo changes the owner and the group of some my files and now I can't enter in X Ali79 Linux - Software 5 12-10-2004 01:01 PM
How to change owner and group in a directory to include subdir and all files Lakota Linux - General 2 07-15-2004 09:35 AM


All times are GMT -5. The time now is 07:18 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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration