OSETC TECH

Linux:How To Set UP A Shared Directory

How to share a directory among users in linux, it means that if there is a good way to share a directory between local users, this post will show you on how to use chmod command to setup a shared directory.

Linux Set UP Shared Directory


Firstly, you need to create a few users and one group and  create  a shared directory, then add users into group and specified user’s home directory as that shared directory. last, using chmod command to change user or goup’s permission for shared directory.  the detailed steps are as followss:

step1: create a shared group named as “agroup”

[root@devops ~]# groupadd agroup

step2: make a shared directory under /home directory named as “adir”

[root@devops ~]# mkdir /home/adir

step3: create a user account “atest”  and add to  group “agroup”

[root@devops ~]# useradd -d /home/adir -g agroup -m atest

[root@devops ~]# passwd atest

step4: add another user “btest”  or the rest user and specify the same home directory(/home/adir)

[root@devops ~]# useradd -d /home/adir -g agroup btest

[root@devops ~]# id btest

uid=802(btest) gid=801(agroup) 组=801(agroup)

step5: Change ownesrship of shared directory and its subdirectories using chown comand, changed ownership as atest:agroup

[root@devops ~]# chown atest:agroup /home/adir/

[root@devops ~]# ls -ld /home/adir

drwxr-xr-x. 2 atest agroup 4096 6月  30 03:55 /home/adir

step6: Set the SGID for shared directory and make the directories group-writeable permission

[root@devops adir]# chmod -R 2775 /home/adir

[root@devops adir]#

done….