Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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.

share|improve this question
    
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 Jun 17 at 6:31
    
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 Jun 17 at 6:51
add comment

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

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.