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 love Linux and everything she stands for; however, unfortunately I grew up with Windows. Thusly so I have learned very bad practices (such as NT Authority will protect me). I have several Linux VPS's for personal and educational uses and I manage all of them from the command line. Through the management of these servers I have learned very painful lessons of the power of the Root user. Such as:

  • rm -d -R /*
  • chown www-user:www-user -R /*
  • Etc.

I've only removed my root directory twice, but just last week I changed the permission of the whole drive - effectively locking the Root out.

Now I know that I should never be logged in as Root, but most of the time I have to deal with files that only the Root owns so I sudo and run the command.

So my question is, is there a way to prompt the user (who is root, or sudo'ed) when a potentially hazardous command is executed, so the user may rethink their decision? Possibly through scripts in Bash, or a different sudo wrapper.

Or (I ask this hopefully, and very simplified) is there a way to set up permissions where instead of a two tier user system (Root user, regular user) there is a three tier system like in Windows (NT Authority, Administrator, other User). Basically is there a way to keep the ability of System administration, but restrict access to some system files.

share|improve this question
    
You could create a new group, add some user to it (an admin type of user, that you want to restrict access for), and then in your visudo file (as root type visudo) add the group to allow specific sudo commands. That at least somewhat gets you there. That doesn't warn you that you are about to do something stupid, but I think if you are prompted for your password to run a command, you should make sure you know what it's doing. –  nerdwaller Sep 3 '13 at 0:16
    
I believe I already have this setup, I have an admin group that is able to sudo. I run only as that admin, sudo'ing when needed. Unfortunately Ubuntu caches passwords after the first sudo, so after sudo'ing the first time, all other commands will just execute. –  Mark Lopez Sep 3 '13 at 0:29

3 Answers 3

up vote 1 down vote accepted

Get in the habit of doing an ls before you issue a command meant to work recursively or one that is dangerous. You can then see what files will be affected before proceeding.

rm supports the -i switch (causing it to prompt you) as well as --preserve-root (makes it fail on root) which should give you a small margin of safety. Other commands may have similar options. You can have these always be present with an alias rm=rm -i --preserve-root command, and may want to put that in your ~/.profile or ~/.bashrc so it is there every time you invoke your root shell.

share|improve this answer
    
Well most of my issues are not from being in the wrong directory, but adding an extra slash and not the dot (/* vs * vs ./*). I like your idea of aliasing rm. Quick and simple. I know of a lot of commands on linux that can destroy the system - some do not have extra commands like rm. Therefore, I was hoping for a global, fix all, sudo wrapper for most known linux commands to prevent that bad chown command. –  Mark Lopez Sep 3 '13 at 4:46

If you (or someone else on the system) has a perennial problem with making sysadmin mistakes like this, and it's important that you retain your data, you might want to look into keeping your meaningful data on nilfs. There are a few security implications to be aware of on log-structured filesystems; for instance, it's harder to really permanently purge something from disk... but on the other hand, it's really easy to recover from an "oops" like rm -rf /.

share|improve this answer
    
My VPS is running OpenVZ, so another filesystem is unfortunately not possible. If I was running a dedicated server I would go for your idea, or some other mirroring filesystem. –  Mark Lopez Sep 3 '13 at 4:38

SELinux does what you are asking for, e.g. preventing rm -rf /*. Also, the zsh shell asks for confirmation before doing a rm *, in order to protect against typos like rm * .txt.

share|improve this answer
    
SElinux appears to be broken on the modern Ubuntu builds, AppArmor seems promising though. –  Mark Lopez Sep 3 '13 at 4:33

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.