Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

What are the technical differences between the two? The only thing I noticed is that

sudo su

requires you to enter your own password (assuming you're not root)

While

su root

requires you to enter root's password. However both seem to log you into the root user account.

share|improve this question
    
Looks like a duplicate of askubuntu.com/questions/70534/… –  Sergey Dec 8 '11 at 13:22
    
sudo su root -- the best of both worlds! –  William Jackson Dec 8 '11 at 14:27
add comment

4 Answers

up vote 3 down vote accepted

The second command cannot be executed in a default Ubuntu installation, where the root account is not enabled.

But supposing you have unlocked the root account giving him a password, the two commands could only differ in the environment and shell variable set, I think. Compare the output of env in the two situations, and maybe also the output of set to see the differences.

share|improve this answer
add comment

There's a subtle difference between the two. su root (which can be shortened to just su) runs the su command as the user who invoked it. sudo runs the specified command (su) as root. Running su as root is essentially a no-op, though it probably starts a new shell. Running sudo -i is a cleaner (in my opinion) way of running sudo su.

Also, as pointed out previously, there is no root password on a default Ubuntu installation, so invoking su by itself will fail.

share|improve this answer
    
Just a clarfication. It's not really a no-op. It does go through the whole su process. There is a difference between sudo su and sudo bash. –  user606723 Dec 8 '11 at 15:50
add comment

Another difference; the sudo command uses YOUR password and you have to be authorized in the /etc/sudoers file. The sudoers file defines what commands you are allowed to execute using sudo. The su command uses the ROOT password. which must be known.

Depending on options you can pick up roots environment or carry yours forward.

I use "sudo bash" to get a root shell. That is almost identical (maybe is, I am not sure) to "sudo -i". The environment is controlled like this "sudo su - other_user" gets the environment for other_user. But "sudo su other_user" carries your environment forward under the UID of other_user. That means your aliases and such will be available.

Also, auditing results are different in the audit logs when using su versus sudo. More tracability with sudo. Lastly, for su you give the root password around and have a maintenance pain. If you authorize people with sudo, you just update the sudoers file to add or remove people and they only have to remember their own password. Sudoers also allows you to decide what others can do.

share|improve this answer
add comment

sudo -i is how you do it, at least from 11.00 on, not sure about previously or after 12.04.

arries your environment forward under the UID of other_user. as said previously

share|improve this answer
add comment

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.