What is the difference between su and sudo?

QuestionsQuestions8 SkillsProUser Account ManagementSep, 19 2025
0217

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/sudoers file.

Summary:

  • Use su to switch users and get a new shell.
  • Use sudo to run specific commands with elevated privileges without switching users.

If you have more questions or need further clarification, feel free to ask!

0 Comments

no data
Be the first to share your comment!