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.
There's a subtle difference between the two.
su root
(which can be shortened to justsu
) runs the su command as the user who invoked it.sudo
runs the specified command (su
) as root. Runningsu
as root is essentially a no-op, though it probably starts a new shell. Runningsudo -i
is a cleaner (in my opinion) way of runningsudo su
.Also, as pointed out previously, there is no root password on a default Ubuntu installation, so invoking
su
by itself will fail.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 ofenv
in the two situations, and maybe also the output ofset
to see the differences.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.
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