Creating a Shared Directory for Multiple Users on Linux

Pragadeeswaran Gnanasekaran
2 min readJul 11, 2024

--

In a multi-user Linux environment, it’s often necessary to create a shared directory where multiple users can collaborate by placing and accessing files. This ensures seamless teamwork and efficient file management across different user accounts. In this guide, we’ll walk through the process of setting up such a shared directory with appropriate permissions.

Step 1: Creating the Shared Directory

The first step is to create a dedicated directory where users will share files. For demonstration purposes, let’s create a directory named /var/sharedfiles.

sudo mkdir /var/sharedfiles

Step 2: Setting Up a Group for Access Control

Next, we’ll create a group specifically for managing access to this shared directory. This group will allow members to both place files into the directory and access files placed by others.

sudo groupadd sharedgroup

Step 3: Adding Users to the Group

Once the group is created, we need to add the relevant users to it. For example, let’s add users go, myread, and oracle to sharedgroup.

sudo usermod -aG sharedgroup go
sudo usermod -aG sharedgroup myread
sudo usermod -aG sharedgroup oracle

Step 4: Setting Permissions and Ownership

Now, we’ll set the appropriate permissions and ownership for the shared directory /var/sharedfiles.

sudo chown root:sharedgroup /var/sharedfiles
sudo chmod 2775 /var/sharedfiles

Explanation of permissions (chmod 2775):

  • 2 in the first position sets the setgid bit. This ensures that files created within the directory inherit the group ownership of the directory itself (sharedgroup).
  • 775 gives the owner (root) and group (sharedgroup) full read, write, and execute permissions on the directory, while others have read and execute permissions.

Step 5: Verifying Access

Users can now place files into /var/sharedfiles and access files placed by others within the same directory. Here’s how they can verify their access:

sudo -u go touch /var/sharedfiles/testfile.txt
sudo -u myread touch /var/sharedfiles/testfile2.txt
sudo -u oracle touch /var/sharedfiles/testfile3.txt

Users can access files placed by others:

sudo -u go cat /var/sharedfiles/testfile2.txt
sudo -u myread cat /var/sharedfiles/testfile3.txt
sudo -u oracle cat /var/sharedfiles/testfile.txt

Conclusion

Setting up a shared directory with appropriate permissions on Linux involves creating a directory, setting up a group, adding users to the group, and configuring permissions and ownership. This setup ensures that multiple users can collaborate effectively by sharing files while maintaining security and access control.

By following these steps, you can create a centralized location for collaborative work among users, enhancing productivity and workflow efficiency in a Linux environment.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

No responses yet

Write a response