Linux: Share a directory between local users

I spent a few hours yesterday trying to get this done but ran into several problems, and worst of all, I couldn’t find one single post addressing all permission problems associated with allowing several users access to the same directory for read/write operations.

The best way of creating a shared directory is to create a user and group, and then a home directory. Make other users members of the new group and set permission inheritence to propagate to child objects regardless of the user who is creating or uploading the file.

User name is shareowner and group, sharedhome.

Create a user, group and home directory for the new user:
useradd -d /home/shareowner -g sharedhome -m shareowner

The above command creates a user and group as user’s primary group. I wouldn’t create a password for the user if I don’t want the user to actually be able to logon to the server. Once the home directory is created I will add the existing users to the new group:
usermod -G sharedhome existinguser1
usermod -G sharedhome existinguser2

and so on. Note that I use -G and not -g, as I want users to become additional users of the new group. Now we set permissions for the new directory… I make shareowner the owner, and sharedhome the group that owns the directory:
chown -R shareowner:sharedhome /home/sharedhome

Then I use umask and chmod to force all files in /home/sharedhome to inherit permissions from the top directory:
umask 002
chmod -R g+s /home/sharedhome

That’s it. Now existinguser1 and existinguser2 should have read/write permission to /home/sharedhome directory.

CC0 1.0 To the extent possible under law, the creator has waived all copyright and related or neighboring rights to this work.

4 thoughts on “Linux: Share a directory between local users

  1. picek says:

    I would recommend using -a option when executing usermod:
    usermod -aG sharedhome existinguser1
    without it usermod replaces current list of supplementary groups with given, here – with ‘sharedhome’. Using -a will make it append ‘sharedhome’ to list.

Leave a Reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.