5

I have this structure:

/home/the_user/folder/subfolder

and I would like to have read and write access to it, but I want to be unable to read or write anything above it, that is

/home/the_user/folder

Is that possible?

2 Answers 2

3

It's better to do this in a location other than home such as creating the folder structure in / but here it goes:

Set the owner of subfolder as the user you want to have read and write permissions.

chown user /home/the_user/folder/subfolder
chmod u+rwx /home/the_user/folder/subfolder

Set execute for others on /home the_user and folder and make sure that there is no read and write for the user.

chmod +x for each of them and chmod -rw for the user.

That will allow the user to traverse the above directories but not read them or write to them while allowing him to read and write to subfolder.

Once again, I recommend against doing this in /home and suggest that you create the directory as a subfolder of root such as:

mkdir /mnt/folder

....and use my answer there instead of potentially making a mistake and giving permissions to someone's home directory.

2
  • 2
    No, this is wrong. With x permissions on /home/the_user/folder, you can access the files in it as their permissions permit. You can't list the directory contents, but if you know our guess the name of a file, you can check whether it exists, and can access it subject to that file's permissions. Commented Apr 12, 2018 at 7:46
  • 1
    My answer isn't wrong. It just doesn't cover every possible scenario which can be said of many of the answers in Stack Exchange especially when it comes to access and user rights. The one flaw is that a user can guess a filename in one of the higher folders and see that it exists by using lson the file itself but he still can't access it unless he has permissions. As the OP doesn't want that, it's up to him to make sure that the permissions don't allow that access. My answer doesn't allow him to list the directory contents for the higher directories so it effectively does what he wants. Commented Apr 12, 2018 at 13:31
2

Another approach is to mount the folder to a folder the user have access to.

Say we have the folder /home/the_user/folder/subfolder you want to show to user cat without disclosing anything else in your home:

mkdir /home/cat/subfolder
chown cat /home/the_user/folder/subfolder
sudo mount -o bind /home/the_user/folder/subfolder  /home/cat/subfolder

Should do the trick.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .