0

Consider two user accounts user1 and user2 on one Linux machine. I want user2 to be able to have read and write access to a folder in user1 home directory.

So far created a group for both users and added both users

groupadd twousers
usermod -a -G twousers user1
usermod -a -G twousers user2

then changed the group and the path and changed the permission

chgrp twousers /home/user1/folder
chmod g+rwx /home/user1/folder

Unfortunately user2 is still unable to access the folder /home/user1/folder. It seems to be quite simple but somehow I am lost. What am I missing?

  • Something often missed is the permissions on the parent directory. It's possible that /home/user1 has no execute permission for user2. The simplest way to fix this would be chmod o+x /home/user1 since I guess you don't want to change the group on the home directory you need to give everyone execute permission on it. – Philip Couling Mar 20 at 23:08
  • I swear that this exact same question was asked earlier this year but I wasn't able to locate it. Anyway, the other user can't access the directory because the home directory of each user is only traversable by the respective user. Rather than having the folder inside of another user's home, just put it in mnt and change the permissions in that directory or create an NFS export that only the two users can access. – Nasir Riley Mar 20 at 23:11
0

The problem you are experiencing was to expect. Indeed, you are trying to share a folder inside another user home folder, which, for obvious security reasons, is (and should) only be accessible to the owner (and root, but that's another story).

In order to solve your problem, you should create another folder, where the potential parent(s) folder(s) will have the same permissions for both users e.g. /data/folder_to_share.

Here is a brief step-by-step example:

  • Create a parent folder (not necessary but it's for the sake of the example):

    # cd /
    # mkdir data
    
  • Create a shared subfolder:

    # cd data
    # mkdir shared_folder
    
  • optional : at this stage you could copy the content of the future shared folder into shared_folder.

    # cp -p  /path/to/folder/* /data/shared_folder/
    
  • Create a group share and two users bob and alice to it:

    # group add shared
    # usermod -aG share bob
    # usermod -aG share alice
    
  • Recursively change group folder ownership:

    # chgrp -R shared /data
    
  • Adding reading, writing and executing (only for files already executables) permissions for the group shared:

    # chmod -R g+rwX /data
    
  • Bob and Alice will now be able to do whatever they want inside the folder shared but as well in data.

Depending on your use case, you could just have one level but this example shows how the parent folder permissions can affect a folder deeper into the filesystem and allows for more scalability and granularity.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.