Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I would like to know how we can restrict rm -rf /on CentOS machines?

share|improve this question
1  
By default it shouldn't do any harm on recent versions as long as you don't use --no-preserve-root. –  Marco Jun 1 '13 at 20:27
    
If you're in doubt, set up a VM and have some fun with rm just to get a feeling about what works and what doesn't. –  Marco Jun 1 '13 at 21:14
    
[See this similar question][1] about another command. [1]: unix.stackexchange.com/questions/77696/… –  Hauke Laging Jun 1 '13 at 21:33
4  
Create /usr/local/bin/rm which plays Jingle Bells instead of removing files. –  tripleee Jun 2 '13 at 6:17
    
"Restrict" how? –  Michael Kjörling Aug 15 '13 at 7:34
show 1 more comment

closed as too broad by bahamat, Anthon, slm, Zelda, jasonwryan Jan 18 at 8:21

There are either too many possible answers, or good answers would be too long for this format. Please add details to narrow the answer set or to isolate an issue that can be answered in a few paragraphs.If this question can be reworded to fit the rules in the help center, please edit the question.

2 Answers

I think the best way to restrict directories is to use sudo. If you add an user to the sudoers file and they go rm -rf --no-preserve-root / then there isn't much you can do, but normal users (not in the sudoers file) won't be allowed to do that at all.

share|improve this answer
add comment

Check out Safe-rm, it's basically a wrapper around rm that skips by default important directories (/, /bin, etc):

$ rm -rf /usr
Skipping /usr
share|improve this answer
1  
The danger to such an approach (regardless of the exact tool; even alias rm='rm -i comes with such a caveat) is that you run the risk of getting used to having such protections in place, and then don't realize until it's too late when you're working on a system that doesn't have them. Instead, consider the fact that with great power comes great responsibility. Being logged in as root should not be taken lightly, and even as an ordinary user, rm -rf ~ can do quite a bit of damage if you don't have current backups. Moral of the story: have backups! –  Michael Kjörling Dec 16 '13 at 19:25
add comment

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