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/

OR

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

See also:

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s