Linux setup shared directory

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/


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

See also:

🥺 Was this helpful? Please add a comment to show your appreciation or feedback.

nixCrat Tux Pixel Penguin
Hi! 🤠
I'm Vivek Gite, and I write about Linux, macOS, Unix, IT, programming, infosec, and open source. Subscribe to my RSS feed or email newsletter for updates.

9 comments… add one
  • jon May 31, 2010 @ 7:43

    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

  • Stephen Jul 6, 2010 @ 16:32

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

    Thanks for the tutorial!

    • svenn Jul 13, 2015 @ 13:01

      Actually both are correct.

  • Matt Dunlap Jul 27, 2010 @ 4:03

    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.

  • james Sep 9, 2010 @ 20:05

    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

    • wzhd Oct 23, 2015 @ 12:33

      Just wondering: is there any security implications by setting umask to 002?

      Can I set it just for a certain directory?

      • Jorge Suárez de Lis Nov 25, 2015 @ 12:08

        But this don’t prevent the users from using a more restrictive umask, or from using faulty graphical clients that use another permissions.

        The only solution I found is to check the permissions everytime someone changes the permissions of a file/dir, creates a file/dir, or modifies a file/dir with inotify and then set the permissions accordingly. Unfortunately, this task is very difficult, because some clients change the permissions *after* writing all the file, some when creating it… and you can run into some infinite loops, too. So some in-field testing will be required.

  • Matt Dunlap Sep 9, 2010 @ 21:04

    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.

  • sadegh Dec 28, 2011 @ 7:41

    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?

Leave a Reply

Your email address will not be published. Required fields are marked *

Use HTML <pre>...</pre> for code samples. Your comment will appear only after approval by the site admin.