0

I just learned file permissions in a textbook and am still figuring out how it all works together. Especially with top level directories and subdirectories. It seems to me that if I restrict write access for a subset of users to a top level directory, then those same users can not write to any subdirectory inside of it. Here is the file structure.

drwxrwxr-x 4 brian brian 4096 Feb 22 17:17 tdir
drwxrwxrwx 2 brian brian 4096 Feb 22 17:17 tdir/dir1
drwxrwxrwx 2 brian brian 4096 Feb 22 17:17 tdir/dir2

sudo -u casey touch ~brian/playground/tdir/dir1/tfile
touch: cannot touch '/home/brian/playground/tdir/dir1/tfile': Permission denied

Say I do not want world users to be able to change the contents of tdir/ but I want them to be able to alter the contents of its subdirectories dir1 and dir2. I'm assuming this is a fairly common situation, but with my current permissions I still get permission denied when a world user tries to create files within dir1 or dir2. How can I get around this and what is the typical way to deal with the situation? Thanks in advance.

  • Show us a transcript of you trying to write to tdir/dir1. With evidence of permissions. cd tdir; ls -la; cd dir1; touch zzzz. Add it to your question. – ctrl-alt-delor Feb 22 '18 at 22:41
  • You may also find this useful unix.stackexchange.com/questions/101263/… – ctrl-alt-delor Feb 22 '18 at 22:44
  • Can you do the full sequence, so I see permissions (context is everything). Yes you need to mod it to add sudo, in your case. – ctrl-alt-delor Feb 22 '18 at 22:46
  • sudo does not accept built in commands. cd is a built in command so I cant really do as you asked. – bmcentee148 Feb 22 '18 at 22:52
  • The evidence of permissions is given above in my original post. It shows the read write and access permissions for user group and everyone else. Being another user will not change those. I'm a little confused what you mean. – bmcentee148 Feb 22 '18 at 22:58
0

Here brian can read and write all 3 directories.

Others can read all, and write dir1 and dir2, but not tdir.

I see no reason that any user could not write to tdir/dir1 or tdir/dir2


I have added a comment asking for more info.

  • 1
    It was because brian's home folder restricted execute access(entering) from world users. Since the directory tdir and subsequently dir1 and dir2 lived inside of brian's folder I am assuming since world users could not access my home directory they can not access any of the subdirectories since the path was "cut off" in a way. After I allowed execute access for brian's home directory I had no problem with any other user writing to tdir/dir1 or tdir/dir2 as you stated. – bmcentee148 Feb 22 '18 at 23:13
  • Following my instructions would have found that, very quickly. – ctrl-alt-delor Feb 22 '18 at 23:17
  • As i stated above I cant just do sudo -u casey cd <dir> as you told me to. Try it yourself. Command not found error is thrown because cd is a shell built in. You would have realized that yourself had you read my comment stating it. And no it would not have because your instructions do not have any permissions listed until I was inside tdir, which allows access by all users. – bmcentee148 Feb 22 '18 at 23:42
  • "cd tdir; ls -la; cd dir1; touch zzzz" permissions for brian's home folder would never be listed. What are you talking about? – bmcentee148 Feb 22 '18 at 23:43
  • Add yes that is true, but then we would have more information, to try something else. like sudo -u casey bash -c "cd tdir; ls -la; cd dir1; touch zzzz" Well we lives and learns, well we lives anyway. – ctrl-alt-delor Feb 22 '18 at 23:50

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.