Linux setup shared directory

by on January 11, 2006 · 6 comments· LAST UPDATED January 11, 2006

in

Sharing a directory among users in same group is one of the essential tasks. You need to use chmod command and add user to appropriate group. To make idea clear here is an scenario:

  • /home/myproj : is shared directory
  • usr1, usr2, ... usrN : would like to work and share files in /home/myproj directory
  • padmin : Main project administrator user

Step # 1: Create a shared directory /home/myproj
If this directory does not exist then create it:

# mkdir /home/myproj

Step # 2: Create the group shared group
You need to create a new group. Let us assume group name is myproj

# groupadd myproj

Step # 3: Add user project administrator (padmin) and setup password:

# useradd -d /home/myproj/ -g myproj -m padmin
# passwd padmin

Step #4: Add rest of users to group myproj

# useradd -d /home/myproj/ -g myproj usr1
# passwd usr1

Add second user:

# useradd -d /home/myproj/ -g myproj usr2
# passwd usr2

... and so on...

Step #5: Setup permission on /home/myproj directory as follows:
(a) Setup group ownership to myproj group:

# chown -R padmin.myproj /home/myproj/

(b) Setup full permission for group and owner on a directory:

# chmod -R 775 /home/myproj/

(c) Setup sgid bit. So what is sgid bit? Normally whenever you creates file in a directory it belong to default group of user. When a file is created in a directory with the sgid bit set it belogns to the same group as the directory. The result is all users of myproj group can create/alter files in /home/myproj directory:

# chmod -R 2775 /home/myproj/

OR

# chmod -R g+s /home/myproj/

See also:

TwitterFacebookGoogle+PDF versionFound an error/typo on this page? Help us!

{ 6 comments… read them below or add one }

1 jon May 31, 2010 at 7:43 am

My problem is that when usr1 creates a file foo in /home/myproj he then becomes the owner of foo and no one else can edit it. How can I cause files and dirs under /home/myproj to be accessed (read write del) by all the users in the group?

ls -l /home/myproj
-rw-r–r– 1 usr1 users 5 May 31 03:37 foo

Reply

2 Stephen July 6, 2010 at 4:32 pm

Hey, should be : instead of . in 5.a.

Thanks for the tutorial!

Reply

3 Matt Dunlap July 27, 2010 at 4:03 am

I made a web group, added the users.

Made a directory called test
chown root.web test -R
chmod 2775 test -R

I can see the guid bit set, but when I make a file in the test directory, it does not have group write permissions? the file is root.web but the permissions are 644.

I thought since the directory was 2775, the files that are created inside are 664… Did I do something wrong?

Group members need to add files and then other group members need to write to them.

Reply

4 james September 9, 2010 at 8:05 pm

The reason this doesn’t work as Jon and Dunlap want:

Setgid when set on a directory (e.g., the 2 in 2775) basically only specifies the default group for new files not their permissions. The permissions will still be dictated by umask; so you should set umask 002 (so new files are created with read/write permission for everyone in the group by default — the normal umask is 022).

This is normally done in /etc/profile or in each users ~/.profile or ~/.bashrc

Reply

5 Matt Dunlap September 9, 2010 at 9:04 pm

I actually found that my issue had to do with php ssh2. I was using Wordpress auto upgrade feature and the files would get created but without the correct file permission. I was able to use filezilla sftp for the developers to upload and create files which worked.

I made a change to the mask in the wordpress config that created group writable files.

Reply

6 sadegh December 28, 2011 at 7:41 am

i have a drive in windows server 2003 and I want share this drive for one user
this user use a linux Red Hat OS and i want just this user modify this drive and other network user can’t any modify this folder

How can i ddo this
by Active directory User How?

Reply

Leave a Comment

Tagged as:

Previous Faq:

Next Faq: