Thursday 30 March 2017

sudo su

Following the instructions to do some work on some Linux servers I've been using sudo su quite a lot lately. Sure I know what the sudo command and the su command do, but it was not so clear to me how both commands combined work, so I was starting to feel a bit like a monkey each time I typed it. I finally understand what is exactly going, so no more monkey feeling :-)

The facts:
When running sudo su I just type the password of my current user (that is declared in the sudoers file) and now I will be running as root in the shell (without having typed the root password that su should request).

The how:

  • When invoking su without passing a user as parameter it will be just the same as doing su root
  • su root should ask me for the root password, unless that the su command is already being run as root. That's the magic part.
  • When running sudo if my current user is declared in the sudoers file I will be asked for his password, and the command that I'm tryng to launch will run as root. So the su command will be run already as root, and hence I will not ask for the root password.

No comments:

Post a Comment