Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
How to Create a Shared Directory for All Users in Linux?
When multiple users need access to the same set of directories or files, we need to create shared folders in Linux. Linux uses users and groups with specific permission levels to enable secure data sharing. Below are the steps to create shared folders where multiple users can read and update files.
Step 1: Create the Shared Directory
First, create the directory that will be shared. The -p flag creates the directory and ignores errors if it already exists ?
sudo mkdir -p /bigproject/sharedFolder
Step 2: Create a User Group
Create a user group that will contain all users who need access to the shared folder ?
sudo groupadd SharedUsers
Step 3: Set Group Ownership and Permissions
Assign the new group as owner of the shared folder and set appropriate permissions. The 2775 permission includes the setgid bit, ensuring new files inherit the group ownership ?
sudo chgrp -R SharedUsers /bigproject/sharedFolder sudo chmod -R 2775 /bigproject/sharedFolder
Understanding the Permission 2775
Step 4: Add Users to the Group
Add existing users to the SharedUsers group so they can access the shared folder ?
sudo usermod -a -G SharedUsers user1 sudo usermod -a -G SharedUsers user2
For new users, create them and add to the group in one command ?
sudo useradd -G SharedUsers user3
Step 5: Verify the Setup
Check the directory permissions and group membership to ensure everything is configured correctly ?
ls -la /bigproject/sharedFolder groups user1
Testing the Shared Directory
Users should now be able to create and modify files in the shared directory. When a user creates a file, it will automatically belong to the SharedUsers group, making it accessible to all group members ?
# As user1 echo "Test content" > /bigproject/sharedFolder/testfile.txt ls -la /bigproject/sharedFolder/testfile.txt
Conclusion
Creating a shared directory in Linux involves creating a group, setting proper permissions with the setgid bit (2775), and adding users to the group. The setgid bit ensures new files automatically inherit group ownership, maintaining proper access control for all shared content.
