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
6
  • Is the user that cannot create a file in the directory able to navigate (i.e., cd) to that directory? Oct 7, 2017 at 5:26
  • @AndyDalton yes
    – Vipin
    Oct 7, 2017 at 5:31
  • Does a file with that name already exist, and if so is it owned by a different user? Oct 7, 2017 at 5:34
  • Please check this answer. https://unix.stackexchange.com/questions/369012/umask-not-working Oct 7, 2017 at 5:39
  • 2
    @user3411123 the question you gave looks like completely different to me
    – Vipin
    Oct 7, 2017 at 5:47

3 Answers 3

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
  • 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 7, 2017 at 6:01
  • If the OP can get to the directory in question, parent permissions have no more relevance. Nov 12, 2018 at 7:52

You must log in to answer this question.

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