How to create a Shared Folder between two Local User in Linux?¶
This article shows how to set-up a shared folder between two local users in Linux. The shared directory/folder will be accessible to both the users, they will be able to read/write each other’s file.
Let us create shared directory /home/shareFolder for user
Bob and Alice and add them to a common group named
projectA.
Note: You can create the uses Bob and Alice using following commands:
$ sudo useradd Bob
$ sudo passwd Bob
$ sudo useradd Alice
$ sudo passwd Alice
So, start by creating common group using
groupaddcommand.$ sudo groupadd projectANow, create shared directory and change group for it using
chgrpcommand.$ sudo mkdir /home/sharedFolder/ $ sudo chgrp projectA /home/sharedFolderAfter this we need to change appropriate permissions for the shared directory using
chmodcommand.$ sudo chmod 770 /home/sharedFolder/Here 770 permission means:
7 – owner has rwx permissions. 7 – directory groups have rwx permissions. 0 – others have no permissions.We also need to set the SGID(Set-Group-ID) bit for the sharedFolder directory, now all newly created subdirectories/files under sharedFolder will inherit sharedFolder permissions.
$ sudo chmod +s /home/sharedFolderFinally we add users to the common group with whom to share the folder
$ sudo usermod -a -G projectA Bob $ sudo usermod -a -G projectA Alice
Now /home/sharedFolder is accessible to both the user Bob and
Alice. But others can’t access this directory. This directory will be
accessible to only members of projectA group.
Code Permission¶
Each permission is assigned a value, as the following table shows, and the total of each set of permissions provides a number for that set.
Number |
Octal Permission Representation |
Ref |
|---|---|---|
0 |
No permission |
\— |
1 |
Execute permission |
\–x |
2 |
Write permission |
\-w- |
3 |
Execute and write permission: 1 (execute) + 2 (write) = 3 |
\-wx |
4 |
Read permission |
r– |
5 |
Read and execute permission: 4 (read) + 1 (execute) = 5 |
r-x |
6 |
Read and write permission: 4 (read) + 2 (write) = 6 |
rw- |
7 |
All permissions: 4 (read) + 2 (write) + 1 (execute) = 7 |
rwx |
Here’s an example using the testfile. Running ls -1 on the testfile shows that the file’s permissions are as follows −