1

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

6
  • 1
    By default it shouldn't do any harm on recent versions as long as you don't use --no-preserve-root.
    – Marco
    Commented Jun 1, 2013 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
    Commented Jun 1, 2013 at 21:14
  • [See this similar question][1] about another command. [1]: unix.stackexchange.com/questions/77696/… Commented Jun 1, 2013 at 21:33
  • 5
    Create /usr/local/bin/rm which plays Jingle Bells instead of removing files.
    – tripleee
    Commented Jun 2, 2013 at 6:17
  • "Restrict" how?
    – user
    Commented Aug 15, 2013 at 7:34

2 Answers 2

2

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

$ rm -rf /usr
Skipping /usr
1
  • 3
    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!
    – user
    Commented Dec 16, 2013 at 19:25
0

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.

Not the answer you're looking for? Browse other questions tagged .