File create permission error although dir has 777 permission

9,659

Solution 1

Possibly it is overriden by a filesystem access control list. Possibly Linux ACL? You may determine that by using lsfacl.

Get current ACL - You can check permissions for any file or directory with getfacl. See example below.

# getfacl dir/ file: dir owner: root group: root user::rwx group::--- other::---

Set permissions with ACL - You may set "mode" 0777 for a directory with inheritance in the access control lists with setfacl -d -m o::rwx /directory

Solution 2

I ran into this issue as well. For me, the problem was that I had given the necessary rwx permissions to the parent directory:

chmod 777 parent_dir

but I was trying to touch a file in a subdirectory that I didn't had permission to.

> touch parent_dir/subdir/file.txt
touch: cannot touch 'parent_dir/subdir/file.txt': Permission denied

If this is your issue, the command you are looking for is, for example

chmod -R 777 parent_dir
Share:
9,659

Related videos on Youtube

Vipin
Author by

Vipin

I help professional Java developers learn language features so they can get the best Java jobs!

Updated on September 18, 2022

Comments

  • Vipin
    Vipin almost 2 years

    On running command touch file I am getting error

    touch: cannot touch 'file': permission denied
    

    Although I have 777 permissions on the dir where I am trying to create file but still not able to create file with one particular user, some other users can create files there.

    Tried strace to see what might be root cause but not able to to understand strace output. One line and I guess relevant as well of strace output is:

    open("file", O_WRONGLY|O_CREATE|O_NOCTTY|O_NONBLOCK, 0666) = -1  EACESS (Permission denied)
    

    I tried to create file with specific permissions as well but getting permission error, command tried is:

    install -b -m 511 /dev/null file
    
    • Andy Dalton
      Andy Dalton over 6 years
      Does a file with that name already exist, and if so is it owned by a different user?
    • user3411123
      user3411123 over 6 years
    • Vipin
      Vipin over 6 years
      @AndyDalton no file is there with this name I tried with other names as well
    • Vipin
      Vipin over 6 years
      @user3411123 the question you gave looks like completely different to me
  • Vipin
    Vipin over 6 years
    Can you explain this sometimes case, why it might happen ? Although this is not true in my case. Generally users doesn't have access to all parent dirs in hierarchy.