0

I, as a normal user (not root), am trying to create a file in a directory as below:

touch a/b/c/d/test.log

However I get an error: permission denied.

I know that I should chmod for the directory but I don't know what a proper permission is because I don't want to make it 777.
Also, I should chmod for each directory like this:

sudo chmod ??? a
cd a
sudo chmod ??? b
cd b
sudo chmod ??? c
...

Or I should simply do:

sudo chmod ??? a/b/c/d

If I need read and write test.log after creating, what should I use to replace ??? above?

2

You need a minimum of 'execute' permissions on directories a/, a/b/, and a/b/c/, with 'write' permission on directory a/b/c/d/. The execute permission allows you to traverse the directory to get to the next one, you don't need actual write permissions on the intermediate directories. You can use the recursive option to chmod to grant execute permissions:

sudo chmod -R +x a

Do keep in mind that this command will affect all files and all directories within a/, not just the directories you mention.

  • Use +X (uppercase X) instead to only set the x bit on directories, and to files that already have it. – ilkkachu Jan 11 '18 at 16:11
1

example suppose user p1 wants to create a file in /a/b/c/d/

Only Owner and Group have read,write and execute permission but user p1 not in Group list and owner.

At that you time you have 2 options change others permission like below

chmod o+rwx /path_whereyou_want_to_create_file/ means all the users will be having rwx permission so they will be able to create a file.

But for safer side You can acl permission like below so it will give read, write,execute permission only to particular user and path

setfacl -m u:p1:rwx /path_whereyou_want_to_create_file/

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.