Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

If I enter in the password to su when prompted, it doesnt work while sudo su does. Also, when a command is executed using sudo (command), does sudo automatically execute it by root by default (since the man page says sudo, sudoedit - execute a command as another user

michaelxu@michaelxu-server:~$ su
Password:
su: Authentication failure
michaelxu@michaelxu-server:~$ sudo su
[sudo] password for michaelxu:
root@michaelxu-server:/home/michaelxu# exit
share|improve this question

3 Answers 3

up vote 40 down vote accepted

That's because su asks for password of the user you're changing into (which by default is root) while sudo asks for your own user account's password and checks if you are allowed to run the command.

When you run sudo su you are asking sudo to run the command su as root, which gives you the root shell. If you are using only su you will have to know the target user's password to have access.

Using sudo without parameters implies that you want to use root. If you want to execute the command as another user, try sudo -u <username> <command>

share|improve this answer
7  
One other important bit of information to understand the related command sudo su otheruser is that su allows the root to switch into any users without entering their password, while non-root users that runs su have to input the target user's password. sudo su therefore runs su as root, which allows you to get a shell for another user without knowing their password (as long as it's allowed by sudoers). –  Lie Ryan Apr 25 '13 at 9:06
    
So what would my root password be for the "su" command? How come it isnt the password I set in the beginning of the installation? –  agz Apr 25 '13 at 23:23
    
Because your distribution probably didn't set it. You can set a root password running sudo passwd (first provide your user password, then choose a new root password). –  Renan Apr 26 '13 at 0:41
    
So at the moment there is no password?...so basically root is just an account that sudoers can use to make changes to root files? –  agz Apr 26 '13 at 3:18
    
not just that, there are many other services that have to run as root (check ps aux). –  Renan Apr 26 '13 at 6:15

su stands for switch (or substitute) user. With no user name given, it defaults to switching to root. It prompts for the password of the user you're switching to.

sudo is used to run a command as root (i.e., with root permissions), or as other users. It prompts for your password, and checks that you're allowed to use sudo.

When you type su, you're asking to switch to root, and the password that's requested is the root password. When you type sudo su, you're asking to execute the command to switch to root as root, so the password that's asked for is yours.

share|improve this answer

...and to fix the problem of not being able to use 'su' alone, sudo to a root shell, and set a password for root, with 'chpass'.

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.