Imagine that you receive a request for creating a shared folder where Amy, Daniel & Carl will be storing files and all of them will be needing read/write access, there are so many ways to get this job done. In this guide will be going step by step in order to enable read/write access to all specific users in a shared folder in Linux.

 

The easiest way is allocating a common group for all users who will be having read/write access to this shared folder.

  • First of all, We are going to start by creating the folder We’d like to share, example: /var/www/SharedDir

 

 

  • Create the common group, for this example, we are going to call it “friends“.

$ sudo groupadd friends

  • Assuming the users already exist, if not go ahead and create, (Amy, Daniel & Carl). Use a generic password for all users.

$ sudo useradd Amy

$ sudo useradd Daniel

$ sudo useradd Carl

$ sudo passwd Amy

$ sudo passwd Daniel

$ sudo passwd Carl

 

  • Change the folder’s group to “friends”, user -R option which enables recursive operations into subdirectories.

$ sudo chgrp -R /var/www/SharedDir

  • Set the appropriate permissions recursively as well.

$ sudo chmod -R 2775 /var/www/SharedDir

Here is the explanation of the options used along with this command.

2 – Enables the use of the setGID bit, this allows the newly created subfiles inherit the same group as the directory, and those newly created subdirectories will inherit the set GID bit of the parent directory, (How cool is that).

7– Gives full permissions for the owner (rwx).

7– Gives full permissions for the group (rwx).

5 – Gives read/write permissions for others. (rw)

  • Add the users to the group friends.

$ sudo usermod -a -G friends Amy

$ sudo usermod -a -G friends Daniel

$ sudo usermod -a -G friends Carl

Here is the explanation of the options used along with this command.

-a Add the user to the supplementary group.

-G Specifies the group name – If you’d like to add it by the Group id you’ll be using the -g option.

friends – Group Name

Amy, Daniel & Carl – Existing users that you’ll add to the group.

 

That’s it, I told you it will be easy, here is a tip you’ll love:

  • Create more users and add them to the directory group in a zap.

$ sudo useradd -m -c “John Doe” -s /bin/bash -G friends jdoe

$ sudo useradd -m -c “Michelle Smith” -s /bin/bash -G friends msmith

 

 

You’re ready to go and start creating your shared folders across your Linux environment.

Buy me a coffeeBuy me a coffee