11

Asking because of curiosity. :)

When I type

sudo su

It asks for my user password. And when I type just

su

It asks for the root user password. But both the commands directs me to the root terminal. Then why is there such a difference?

  • 1
    @muru The OP is asking difference between su and sudo su not sudo -s or sudo -s – Maythux May 08 '15 at 07:58
  • 2
    @NewUSer read again. – muru May 08 '15 at 07:59
  • 1
    There is never a good reason to run sudo su. I've always wondered why this is so commonly suggested in the Ubuntu world. It is clumsy, inelegant and adds needless overhead. Just run su if you've set up the root account or sudo -i if you haven't. sudo su is just silly. – terdon May 08 '15 at 08:43
  • 1
    @terdon Usually when the user is on a corporate LAN the system administrators may not share the root user password with all the employees. In such a scenario its easier for a user to become root by putting sudo su and inserting user password. Since majority of Linux users are workers under corporates, say IT, I guess this could be a reason. :) – Anonymous Platypus May 08 '15 at 09:16
  • 1
    @AnonymousPlatypus no, that's when you use sudo -i, or sudo -s, you might also want to use -E, depending on what you want to do. What you don't want is sudo su. Both because there's no reason to run two programs when one is enough and because that way you can control the resulting environment much better. – terdon May 08 '15 at 09:27

1 Answers1

19

sudo su means run the command su as sudo which means as root. Here the system will ask you for your password since you are a sudoer. After you enter your password, you now have root privileges. So su command won't ask for a password. It's same as if you are a root then su to any other user will not ask for password because you are a root.

When you just run the command su, you are running it as a regular user. Since su means switch to user root, you will be asked for the root password.

Maythux
  • 84,289
  • 2
    This is a good answer so I wont write another but would like to include the following detailed blog post I found http://johnkpaul.tumblr.com/post/19841381351/su-vs-sudo-su-vs-sudo-u-i – Mark Kirby May 08 '15 at 08:01