Setting up shared directories on Linux

Recently I wanted to setup a shared directory to share between certain users on a Linux system. In my context, it was for a Plex media server. I wanted to create a directory where I could add files to it, and the plex user account would be able to access and manage files as needed. To do this, plex needed to read/write access to the files and directories in the shared folder.

However, on most distributions of Linux, the default permissions when creating new files/directories is to give read/write access only to the owner of the files. I needed to find a way to grant write access to plex automatically when creating new files from my normal user account.

i needed to just run three commands to do this

# change the owner of the shared directory to plex
chgrp -R plex /path/to/dir
# set the gid bit only on directories, so new files/directories set to same group as parent
find . -type d -exec chmod g+s {} \;
# set ACL so group has write permissions by default
setfacl -Rd -m plex:rwx /path/to/dir

Then, you need to add your user to the plex group so they can edit this directory too

usermod -a -G plex $USER