3

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
RalfFriedl
  • 8,981
Vipin
  • 163

3 Answers3

2

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

1

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
-1

Some time you have sufficient permission on the current directory in which you want to create file but don't have permission on parent directories in hierarchy .

Please see that once , if there are some permission problems from Root directory to your current directory .

One Other reason may be , check selinux is enabled or not .

  • 2
    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. – Vipin Oct 07 '17 at 06:01
  • If the OP can get to the directory in question, parent permissions have no more relevance. – Chris Davies Nov 12 '18 at 07:52