Permission denied on sudo remove

0

0

I have two users userA and userB. userA has permission over a file named cache. I want to give permission to userB to remove the file. I have made following entry in /etc/sudoers file :

userB ALL=(userA) NOPASSWD:/bin/rm /opt/cache

When I type sudo -u userA /bin/rm /opt/cache, it says permission denied. However cache has 777 permission. Please let me know where I am doing it wrong.

newbie17

Posted 2014-06-17T06:18:41.763

Reputation: 187

Usually /opt/cache is a directory (I see you edited "directory" to "file" but I'm not sure why?). You need rm -r to remove a directory. Also you may get weird errors if /opt/cache is a mount point. Are you using SELinux, by chance? – Jason C – 2014-06-17T06:31:11.897

cache is a file in my case. I mistakenly typed directory there and I am not using SELinux. Also, it's not a mount point. For more clarity please find output of ll : -rwxrwxrwx. 1 userA userA 87475 Jun 17 06:39 cache – newbie17 – 2014-06-17T06:51:01.290

Answers

1

NOPASSWD takes a comma separated list of programs. Do this instead:

userB ALL=(userA) NOPASSWD:/bin/rm

Note that will allow userB to delete any file that userA can delete.

A better, more controlled solution might be to change the owner group of that file to some group that is allowed to delete it, then add the users to that group.

You might also get away with a shell script that deletes that file, and specifying that instead. Not sure though, and take care to ensure that only root or userA can edit that script.

Jason C

Posted 2014-06-17T06:18:41.763

Reputation: 8 273