0

I have a file which I can't seem to copy even though I have permissions as user1

> sudo -u user1 cp item1 some/nested/dir
cp: cannot create regular file 'some/nested/dir/item1': Permission denied

But if I make a copy of it, I can copy it

> sudo -u user1 cp item1 item2
> sudo -u user1 cp item2 some/nested/dir
>
ls -l
total 83464
-rw-r--r-- 1 user1 user1 28487554 Jun 17 21:46 item2
-rw-r--r-- 1 user1 user1 28487554 Jun 17 21:37 item1

I want to test if user1 has permission to do this or not, so that's why I'm using sudo -u user1

  • Wouldn't it be easier to simply log in as user1, and test from there? – somebody Jun 18 at 15:29
  • what is the output of ls -la some/nested/dir? – ctrl-alt-delor Jun 18 at 16:00
  • 1
    To extend on @ctrl-alt-delor : What are the permissions of any directory you copy from and to as well as their parent directories? If any of the parent directories disallow user1 to trespass, this user can have full access to the file itself, but would not be in the position to execute that right as there are no “island permissions”. Every permission extends from the root directory (“/“). – Phoenix Jun 18 at 20:46
  • 1
    This question leaves me with the impression that not everything is as it seems. E.g. why is item2 listed above item1 in the ls -l output? Normally that would be sorted the other way round. Editing such things manually can obscure details that don't seem relevant to the one writing the question, but which may be very important. – wurtel Jun 19 at 7:57
  • Does the destination directory already have something with the name item1 in it? – Kusalananda Aug 1 at 16:24
-1

You are trying to copy the files to the destination directory which down to few sub directories, 'some/nested/dir/item1', I suggest you to check each parent directory has the write permission for your ID.

ls -ld some ls -ld some/nested ls -ld some/nested/dir ls -ld some/nested/dir/item1

If any one parent directory doesn't have write permission then you can't copy and place the files in it.

  • How would you address the fact that copying the copy of the file works, but copying the original fails? – Kusalananda Aug 1 at 16:23

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.