3
[demo@PHP_DEV_57 ~]$ sudo su
[root@PHP_DEV_57 www]# 

Why I can switch to root by simply sudo su, what's the difference between sudo and su?

mattdm
  • 6,550
  • 1
  • 25
  • 48
yoyo
  • 57
  • 1
  • 4

3 Answers3

8

sudo allows one user to run commands with the permissions of another user. By default, on most systems, some users are allowed to use sudo to run commands as root. su requires a user's password to log in as that user, unless it is run by root. Thus, sudo su allows you to pretend to be root in order to log in as root without root's password.

PS: sudo -i is recommended over sudo su - which is recommended over sudo su for most everyday purposes.

Sparr
  • 770
  • 1
  • 5
  • 14
  • +1 for the sudo -i. I was about to add that as a comment to the question. – 3dinfluence Dec 10 '10 at 04:01
  • @Sparr why is sudo -i recommended over sudo su - which is recommended over sudo su? please. Thanks. – AJP Jun 23 '13 at 22:27
  • From the `man su` page. "The optional argument - may be used to provide an environment similar to what the user would expect had the user logged in directly." Obvious advantage there. `sudo -i` vs `sudo su -`? – AJP Jun 23 '13 at 22:29
1

Look at the file /etc/sudoers. It has been configured to allow your user account to execute su (and perhaps other commands) as root under sudo without needing a password. And when run as root, su does not prompt for authentication.

This can be done either on a per-account basis or by group membership. (Typically, by membership in the wheel group.)

mattdm
  • 6,550
  • 1
  • 25
  • 48
1

sudo su lets you use the password for demo@PHP_DEV_57 to get a root terminal (as long as you're listed in the sudoers file). su makes you use the password for root@PHP_DEV_57 (which may or may not exist or be known) to get a root terminal.

Melody Horn
  • 111
  • 3