Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.
[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?

share|improve this question

3 Answers 3

up vote 8 down vote accepted

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.

share|improve this answer
    
+1 for the sudo -i. I was about to add that as a comment to the question. –  3dinfluence Dec 10 '10 at 4: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

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.)

share|improve this answer

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.

share|improve this answer

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.