Skip to content
Advertisement

Making a folder visible for a few selected users in Linux

I would like to share a folder called ‘files’ with user1 and user2 in my Linux account. Is there a way to set the authorizations to read write or execute for only these two users and keep it secure from other users? To my knowledge, it is only possible to do this for a usergroup as a whole.

Thank you

Advertisement

Answer

If your Linux has a “modern” filesystem (ext3/ext4,… )you can achieve this with POSIX ACLs:

  1. Enable ACLs for the FS. –> only required for ext3 and ext4 on kernels older than 2.6.38. All other FS with ACL-support have them automatically activated.

    mount -o remount,acl /
    tune2fs -o acl /dev/<partition>
    
  2. Give user1 access to the folder files: (r/w/x)

    setfacl -m user:user1:rwx /home/philipovic/files
    
  3. Give user2 access to the folder files: (r/w/x)

    setfacl -m user:user2:rwx /home/philipovic/files
    

If your linux does not support ACLs you have to create a group:

  1. Create a group
  2. Add the desired users to that group
  3. chgrp the directory to that group, and give permissions with chmod:

     chgrp groupname /home/philipovic/files
     chmod g+rwx /home/philipovic/files
    

note: in the above examples we are using r/w/x permissions and therefore giving the users/group FULL controll! don’t forgett to change them to the desired permission.

User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement