- What is su?
- How to Use su
- What is sudo?
- How to Use sudo
- Key Differences Between su and sudo
- User Interaction
- Security and Permissions
- Use Cases
- Summary

When using Linux, users often encounter two commands that provide elevated privileges: su and sudo. While they may seem interchangeable, they serve distinct purposes and are utilized in different scenarios. Understanding the differences between these commands can enhance your efficiency and security when working in the Linux command line.
What is su?
The su command, which stands for “substitute user,” allows you to switch from your current user account to another user account in a Linux terminal. When invoked without any arguments, it defaults to switching to the root account.
How to Use su
Using su is straightforward. You simply type the command followed by the username you wish to switch to:
su username
If you want to switch to the root user, you can just type:
su
In this case, the user will need to enter the password for the target user. Failing to enter the correct password will prevent access. One major aspect to note is that when using su, you’ll be dropped into a new shell environment as the targeted user, which can lead to a complete change in your working environment.
What is sudo?
In contrast, sudo, short for “superuser do,” is designed to execute a single command with elevated privileges without switching users entirely. This command allows users to perform administrative tasks while remaining logged in to their account.
How to Use sudo
To use sudo, you prefix the command you wish to execute with the sudo command. For example:
sudo apt-get update
In this scenario, the user must provide their own password (not the root password) for authentication. This is a fundamental design choice that enhances security by reducing the need to share the root password.
Key Differences Between su and sudo
User Interaction
- Password Requirement:
surequires the password of the target user, whilesudorequires your own password. - Session vs. Command:
suinitiates a new shell session for the target user, whereassudoexecutes a single command without changing the user context unless specified.
Security and Permissions
- Granular Control:
sudooffers more control via the/etc/sudoersfile, allowing system administrators to define specific permissions for different users. This means you can grant certain users the ability to run particular commands without giving them full access to the root account. - Audit Trails: Commands executed with
sudoare logged, providing a clear audit trail, which is vital for security and troubleshooting. This feature is absent withsu, making it harder to track which commands were run and by whom.
Use Cases
- Daily Administrative Tasks: For routine tasks like installing software or adjusting service settings,
sudois recommended, as it confines the elevated privileges to a single command. - System Recovery: If you need to access a different user account or perform tasks requiring a complete change in user context,
sumight be more appropriate.
Summary
Choosing between su and sudo boils down to the specific needs of your task. sudo is the ideal choice for occasional command execution with elevated privileges, while su is suited for comprehensive user change scenarios. By understanding these differences, you can use Linux more effectively, ensuring both efficiency and security in your workflows.
Incorporating these commands into your daily practice can significantly enhance your command-line experience, allowing for a seamless blend of functionality and control.