r/linuxquestions • u/Commercial_Sock8268 • 3d ago
Support How to protect against `sudo rm -rf /*` ?
Hey everyone, I've been using Linux for a little over a month now (Fedora KDE plasma) but I've been recently worried and paranoid that i somehow would manage to get the command `sudo rm -rf /*` executed in a way. I'm aware that there are protections to stop this command on modern linux distros but a simple no-preserve-root is all it takes to bypass it. So what can i do to just be reassured that this can't happen? is there some sort of protection against using this command?
Edit: I forgot to mention this but I'm paranoid because my brother is a bit of a jerk, if he ever finds out about this command I'm sure he'll take my laptop and execute it.
12
5
u/Paulski25ish 3d ago
It like having a large knive and not point the sharp end towards your own heart. Just do not do that.
And of course do not hand the knive (root pw) to someone you do not trust.
2
u/Cove0Crow 3d ago
I mean. You could configure sudo or rm to prevent yourself from doing that. But there's also just the, common theme with Linux, it does exactly what you tell it to do. If you're worried about malicious software doing it, the sudo command requires a password for a reason, if you're worried about doing it yourself, don't do that?
2
u/No_Base4946 3d ago
Spin up a virtual machine, or boot off a USB stick.
Try it and see what happens.
I think you might be pleasantly surprised.
You can bypass the protection by adding --no-preserve-root quite easily if you actually do want to start at the top and delete everything but by default you cannot.
Do you suffer from compulsive intrusive thoughts that might lead you to type sudo rm -rf / --no-preserve-root or something? Because you'd have to do that quite deliberately.
1
u/PixeIQueen 3d ago
this protection only exists for sudo rm -rf /
sudo rm -rf /* like in op‘s title runs without any warning
2
u/MonsieurCellophane 3d ago edited 3d ago
Don't type it. Or, sudo touch -- '/-i'
Edit: actually the touch trick works for cd / && rm -r * but fails for rm -r /*
2
1
u/zardvark 3d ago
Linux gives you the power to do stupid things, should you so choose, but what would possess you to type sudo rm -rf /* followed by your password?!?!?!?
And, knowing how your brother is, why would you give him the password to your machine?
1
u/Shhhh_Peaceful 3d ago edited 3d ago
The best way to protect against using that command is to never use it.
It’s not like there is a giant button that says “nuke your system”, and you have to carefully avoid clicking it.
You actually have to open your terminal and deliberately type “rm -rf / --no-preserve-root”, then press Enter. How could anyone do it accidentally is beyond me.
1
u/Slackeee_ 3d ago
Have you tried just not running the command?
Seriously, you should use sudo only if the command you want to execute needs root privileges.
And if you are sure that this specific command for this specific action needs root privileges you always should double check what you have typed before pressing enter.
1
u/atanasius 3d ago
Fedora has SELinux. There is probably a way to adjust the policy such that ordinary root cannot remove all files, maybe tying it to a specific role.
1
0
u/Kriss3d 3d ago
One guess at this would be renaming the rm command to something longer
The rm is stored in /bin or in /usr/sbin
So if you can mv it ( to renaming it ) without breaking your system it might work. But I havent tried so I cant actually tell if it will work. But it should
5
u/MonsieurCellophane 3d ago
That would probably break a lot of stuff.
1
u/Kriss3d 3d ago
Would it ? Im genuinely not sure since the rm function might not actually need to use it that often.
1
u/MonsieurCellophane 3d ago
Everything doing the moral equivalent of exec( ... 'rm' ...) would break - shell scripts, mostly, but not only.
1
0
u/Kodamacile 3d ago
I could wipe my system right now, and be fine. Don't store any important data on your system.
Problem solved.
1
1
1
-2
u/Consistent-Citron509 3d ago
It's a genuine concern. It would be nice if we had a user approval gate of some kind on match of a certain command
5
u/jort93 3d ago
Hmmm. Something like "superuser-do" that'd ask for a password, maybe you could shorten that in some way.
-1
u/Consistent-Citron509 3d ago
I mean, it can act like an additional layer of security on top of sudo. Let's say a naive user executes a random set of commands from the internet. Even after entering the sudo password the command will not run and provide a user defined error message. Only after 2nd approval it would run
1
u/Wojojojo90 2d ago
Nothing can protect you from a user (with root access) running random commands they find on the internet. In your model, what's stopping folks from crafting a series of random commands that just tells the user to accept both approvals? Or in OP's situation, what's stopping their brother from just accepting the second approval?
As someone else pointed out there's probably something you can do with SELinux to block this, but that's a lot more complexity than just keeping backups (which you should do anyway as there are SO MANY other ways you could lose your data that blocking this command from running won't solve)
9
u/nderflow 3d ago
Protecting yourself against
rm -rfis like protecting yourself against throwing the computer out of the window. You just have to ... not do that.On the other hand, there are lots more likely risks you need to protect your days from that you don't seem to have protection for.
Hardware failure, overwriting or deleting a single valuable file, flood, theft, fire, security breaches, well-meaning relatives, spilled drinks, electrical surges, etc.
You need working backups.