The main differences between su and sudo are:
su (Substitute User):
- Purpose: Switches to another user account (default is root) and provides a new shell.
- Usage: Requires the target user's password (e.g.,
su joker). - Environment: By default, it does not load the target user's environment unless used with the
-option (e.g.,su - joker). - Scope: Grants full access to the target user's permissions and environment.
sudo (Superuser Do):
- Purpose: Executes a single command with superuser (or another user's) privileges without switching users.
- Usage: Requires the current user's password (e.g.,
sudo apt update). - Environment: Maintains the current user's environment while executing the command.
- Scope: Allows for granular control over which commands users can run as superuser, as configured in the
/etc/sudoersfile.
Summary:
- Use
suto switch users and get a new shell. - Use
sudoto run specific commands with elevated privileges without switching users.
If you have more questions or need further clarification, feel free to ask!
