Both su
and sudo
elevate privileges assigned to the current user.
The main difference between the two is that su
requires the password of the target account, while sudo
requires the password of the current user. Therefore, it is much safer to use sudo
since it doesn't include exchanging sensitive information.
Additionally, it is advisable to stick to sudo
when performing tasks that require root privileges. By doing so, the current user is only granted privileged for the specified command. On the other hand, su
switches to the root user completely, exposing the entire system to potential accidental modification.
The su
command stands for substitute user, and it is mostly used for switching from one user to another. It does this by starting a login shell in the current directory and environment (su
) or by completely changing to the setting of the target usr (su -
).
The main syntax is:
su [user_name]
or
su - [user_name]
If the command is used without the argument, it switches to the superuser (root) account.