Share a folder between users

I am quite new using Manjaro and this is basically my first time I create a new user and now I have two users: user1 and guest1. I need to share a folder between the users in order that each user can save, copy and paste folders and files into the shared folder. I used this procedure:

$ sudo mkdir /home/0_dataA
$ sudo groupadd compartidos
$ sudo chgrp -R compartidos /home/0_dataA
$ sudo chmod g+s 0_dataA
$ sudo usermod -G compartidos user1
$ sudo usermod -G compartidos guest1
$ sudo chmod 766 /home/0_dataA

When I use any of the users and try to paste a folder or to save a file into the shared folder 0_dataA I become a error: “Error removing file /home/0_dataA/newfolfer. Permission denied.”

Now, I have no idea how to share a folder between user1 and guest1.

Another issue that I get with this procedure is that user1 does not have the administrator permissions anymore. It has standard permissions such as guest1. I think it is because I added user1 to the group compartidos.

Is there any procedure to share a folder between user1, conserving administrator permissions, and guest1, which only have standard permissions.

Any ideas and answer are very welcomed and I appreciated in advance!

1 Like

To avoid permission issues - create a separate structure outside /home

Create group

$ sudo groupadd share_group

Create data structure e.g.

$ sudo mkdir -p /data/shared_folder

Set owner

$ sudo chown root:share_group /data/shared_folder

Set permissions

  • owner → rwx
  • group → rwx
  • other → rx
$ sudo chmod ug+rwx,o+rx,o-w /data/shared_folder

Add the username(s) to the share_group group

$ sudo gpasswd -a $USERNAME share_group
2 Likes

Couldn’t he just use the existing user group of which all users are usually members?

Thank you linux-aarhus, the shared folder works very well now!

I only have an additional question regarding the permissions of user1.
In terms of security, is it required that user1 recovers the administrator permissions or can I leave user1 with standard permissions.
What is the advantage for user1 of having administrator permissions?

You could - but the first user is never member of users group - and from an administrative POV it is easier to control a group for the specific purpose than a default catchall group.

Yes you can - for as long as the user in question is added to the group accessing the shared_folder

1 Like

Keep in mind that files created in the directory with those permissions do not inherrit those permissions which could result in the shared users not being able to access files of the other users…

I would instead suggest to use the setfacl command:

setfacl -m o::rwx,g::rwx,o::rx,d:g:share_group:rwX /data/shared_folder

This will set the same permissions but also force new files/dirs to be modifiable by the share_group group :wink:

You could extend that to not needing any new share_group by repeating the d:g:share_group:rwX for every group of the users needed
Or even use usenames instead of groups by using d:u:username:rwX

2 Likes

This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.