5

I'm trying to give the ubuntu user on my machine the ability to rm folders and files (mainly in the /www/ folder) without the need to invoke a password or the need to use sudo.

I've been following this article and ended up trying this in my sudoers file.

ubuntu ALL = (ALL) NOPASSWD: /bin/rm

This unfortunately doesn't do the trick.

  • 13
    There is no way this will end well... – jasonwryan Jun 26 '14 at 7:10
  • 4
    Connor the answer you accepted has both the right answer and a wrong answer. Guessing from comments it looks like you picked up on the half that was the wrong answer. You should really heed this warning and use the other way instead. – Caleb Jun 26 '14 at 7:35
  • 4
    I agree with @Caleb. Don't get into the habit of using rm (or even sudo for that matter) haphazardly. You will inevitably delete a file that you've been working on all week which hasn't been backed up yet. rm is not something that can be easily undone. Even if you eventually master the forensic techniques necessary to carve out the data (pray you're not on hfs+), your time can never be recovered. The selected answer is wrong because it teaches bad-habit and uses sudo which you specifically wanted to avoid. A correct answer would involve proper configuration of file permissions. – a_arias Jun 26 '14 at 8:14
11

First of all, you should probably consider why this isn't working in the first place. If you don't understand why they are owned as different users there is a good chance that you will be breaking something by attempting to hack around the limitation. It is quite likely that there is a security issue you will be opening yourself up to by doing this.

Additionally, sudo is the right method for a lot of things, but if you are setting it up without a password that is another indication that you are doing something wrong from a security standpoint. Don't assume that because its "your" machine and "you are the only one using it" that you don't need to worry about these things. Especially if you are running a service like and HTTP server, there is a reason the files being served are owned by a different user than you normally use on the system!

All caveats aside, the proper fix for this is to use the normal file system permission levels to give your ubuntu user permission to operate on the files without having to change to another user or escalate to root privilege levels. This is probably easiest done by adding the ubuntu user to the group that owns /www.

# Find out what group owns /www
stat -c %G /www

# Add the ubuntu user to that group
adduser ubuntu <group_that_owns_www>

Now assuming your files have group as well as owner permissions (i.e. 664 or similar for files and 775 for directories) you should be good to go for normal file operations with no special sudo interventions.

Note: After adding a user to a group you have to actually login again in order to for the system to recognize you as part of the new group.

  • the setguid bit is useful for shared group folders as well. – mikeserv Jun 26 '14 at 18:16

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.