Skip to content
Advertisement

Why can’t this user delete this file?

If I do:

JavaScript

I see:

JavaScript

If I sudo to root and then su to jenkins, I should be able to delete this, yes?

Other relevant information about the directory and its parent:

JavaScript

If I do:

JavaScript

then I see than the user “jenkins” has been added to the “root” group:

JavaScript

But if I:

JavaScript

I get:

JavaScript

Why is permission denied?

Advertisement

Answer

As to why the jenkins user can’t delete, the jenkins user needs write permissions on the parent folder of the file you’re looking to delete. This is because you’re actually removing directory entries from the parent folder.

Usually, on most filesystems, deleting a file requires write permission on the parent directory (and execute permission, in order to enter the directory in the first place). (Note that, confusingly for beginners, permissions on the file itself are irrelevant. However, GNU rm asks for confirmation if a write-protected file is to be deleted, unless the -f option is used.)

Source: Wikipedia – Rm_(Unix)

So try running…

JavaScript

And make sure the jenkins user has write permissions on /usr/local/bin

Another way to do it is to modify sudoers to give jenkins user sudo permissions to rm only that file via sudo. Here’s an example giving the user joe the explicit permission to sudo rm the file /usr/local/src/noperms/hi.txt from a directory he does not have write permissions to. But limiting him from deleting anything else in that directory.

For example:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement