23

What is the actual benefit that Ubuntu (or Debian derivatives) achieve by disabling root user?

Everywhere I read, it says to prevent unintentional damages for inexperienced users. I want to know what exactly, since sudo can execute all commands (that I know/use).

So in what case root can cause damage whereas sudo can't?

PS: I know how sudo works.

1

7 Answers 7

33

So in what case root can cause damage whereas sudo can't?

Since you must usually invoke sudo each time you want to do something that requires privileges, the reasoning is that you will "think before you leap", i.e. not just stick sudo in front of something without thinking for a second what the command you're running is going to do.

With su on the other hand, once you're in, you're in. You have carte blanche (an open license) to do anything and everything, and the reasoning is you might forget for a moment that you have those privileges and if you're unlucky, execute something that will seriously affect/damage your system -- if you did not have su privileges, the command wouldn't have done anything serious.

4
  • 9
    The "think before you leap" logic is as naive as thinking users will stop to think when shown a dialog box that says "Do you really want to install TrashTheComputer.Virus: Yes/no?" will reduce malware infection rates. May 11, 2012 at 14:42
  • 11
    @DanNeely - I don't think so. I type a lot of commands, and most of them don't require sudo, so I don't use it. When I do use it, it gives me a moment of pause. Yes, I'm speaking as a programmer, not an average user, but then again, average users don't use the command line. May 11, 2012 at 15:20
  • 2
    @NathanLong not quite true with Linux, the reason this question exists shows an "average user" not understanding why to use sudo over su. Too often, people say "use sudo because it's safer than su" - which is naive to think as it isn't any safer at all. To forget you used su is no excuse, that's just down-right incompetence if you run a command as root accidentally.
    – Ash
    Jan 28, 2016 at 16:08
  • 1
    @ash I still say an average user would not be asking about the comparative security implications of two methods of escalating user privilege. In point of fact, OP has questions on StackOverflow. But OP aside, remembering what you did 15 seconds ago is easier than remembering what you did yesterday, and you could easily have a terminal session spanning days. So yes, it's on you to not forget when you use su, but personally I'd rather not set up bombs than assume I'll remember to disarm them. Jan 28, 2016 at 19:22
17

IMO the major advantages of sudo over su are that sudo has superior logging of what commands were run and sudo gives finer control over what users can do.

su is all or none, but sudo can be configured to allow access to some, but not all commands.

See https://help.ubuntu.com/community/RootSudo for a more complete discussion, including advantages and disadvantages.

11

su -

When logged in as root, any task you start, action you trigger, or random event caused by visiting a certain website, etc. .. will run as super-user.

sudo

When you invoke sudo, as you run a command, only that command will run as super-user.

You will be asked for your password, before the command is executed. So user-interaction by you is also required.

Attempts to invoke sudo can also be logged.

2
  • 3
    Indeed, it asks for the current user's password, which makes it easier to manage the root password. If an account is removed from the system, the root password does not need to be reset. Even better, the root account doesn't even require a password at all, so the root account cannot get compromised through brute forcing it.
    – jippie
    May 11, 2012 at 10:54
  • @jippie general good practice states to remove/block/invalidate the root password and only allow access via sudo su. whilst the hyphen - is a flag accepted by su and treats your shell as if you logged in as the user (runs a different set of environment files i.e. .bashrc/.profile)
    – Ash
    Jan 28, 2016 at 16:13
4

It is about user/password management for sysadmins.

If you have multiple users, they should all have separate accounts and should be able to be tracked using those accounts. This means that people can't hide their identity. Also, if you need to revoke a specific users permissions you don't also have to reset the root password. To give every person in an environment with more than 2 admins the root password makes for a nightmare when one person quits. You must not only change it, but communicate it, etc. All this stuff also has to happen when one of them has a laptop stolen or stuff like that. One account with one password per person makes administration simpler. It is similar to the philosophy behind why each service should have its own account. If one account is compromised, you don't have to reconfigure another dozen services (such as backup tasks) to use a different account.

I also find it personally convenient not to have yet another password to keep track of, lose and have compromised. On RHEL I specifically disable the root account after configuring sudo so I don't have to track it. Once in awhile a user b0rks the sudo file, but that's fixable in single-user mode. (Naturally, it is usually a production machine.)

NOTE: 'sudo bash' will allow you to skip typing sudo for each command...

4
  • I always sudo mc :D
    – Rony
    May 16, 2012 at 3:18
  • The only answer on here worthy of up voting, clearly answers the question without further disambiguating the question or misleading people into a false sense on information.
    – Ash
    Jan 28, 2016 at 16:17
  • @flickerfly, I believe that in "reset the root password for that same user" the "for that same user" should be removed - it will be more accurate that way.
    – Richlv
    Jan 7, 2018 at 0:31
  • @Richlv, You're right. I made the edit you suggested. Not sure what I intended there.
    – flickerfly
    Jan 11, 2018 at 18:15
2

I think first, we need to look into what su and sudo actually are

su - stands for Substitute User. You use this to switch to a shell as another user using that user's password. Commonly used with root. Does not require a password when executed as root.

sudo - allows a permitted user to execute a specified command as another user. Also commonly used with root. However, this allows you to specifically manage what commands may be executed as another use. (For instance, you could give a user the ability to run an init.d script but nothing else.)

Note, you can always run sudo su or sudo -i and that will give you a root shell. However, no root password means no logging in directly as root... which means no one can break into that user.

EDIT: so maybe this answer your looking for is: not having a root password forces you to use sudo, which in turn naturally aligns you with the sudo philosophy which suggests you to enforce greater control over the actions run as root.

1
  • I wrote this myself....
    – user606723
    May 11, 2012 at 18:01
2

In addition there are logging considerations to consider between sudo and su. Being su simply does everything as root with no entry other than one line in the auth log saying you became root.

Sudo on the other hand - always gets logged as your user ID with escalated priveleesw.

0

Usually, logging in as su is easier when performing administrative tasks. However, there is at least one exception: when file ownership matters. If you need a user to be the owner of a file, then log in as that user and use sudo to donwload or copy files. Simple examples are bookmark and wallpaper files. If a user does not own the file, a Firefox "Restore" bookmarks "From File" will fail. When you set a desktop wallpaper, it may not work unless you own the file. Sometimes you can just set privileges or enable as an executable file, but some settings or programs fail if you are not the owner of a file.

1
  • You log in as root and use Firefox to browse the web? I think this is the reason for disabling the root account. It eliminates the possibility of just logging in as root for daily use. May 30, 2012 at 10:10

You must log in to answer this question.

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