What’s the Difference Between Linux su and sudo Commands?
The article explains how the Linux su command switches user identities using the root password, while sudo lets regular users run privileged commands with their own password, comparing their usage, security, logging, permission scope, and suitable scenarios.
1. su Command
The su command switches the current session to another user, typically requiring the target account’s password (often the root password). After entering the password, the user obtains all privileges of the chosen account, e.g.: su When the password is accepted, the shell runs as the root user.
2. sudo Command
The sudo command executes a single command with elevated privileges without changing the user session. It prompts for the invoking user’s own password, not the root password, and the command is prefixed with sudo: sudo apt-get update After password verification, the command runs with root privileges.
3. Comparison
3.1 User Identity
surequires the root password and changes the effective user for the whole session; sudo authenticates the caller with their own password and only elevates the specific command.
3.2 Permission Scope
sugrants the full set of permissions of the target account. sudo can be limited via the sudoers file to allow only certain commands or users.
3.3 Security
Because su shares the root password, anyone who knows it can obtain full system control, posing a security risk. sudo avoids sharing the root password and logs each privileged action, improving auditability.
3.4 Logging
sudorecords the executed command and the invoking user in system logs, while su has no built‑in logging of the commands run after the switch.
3.5 Usage Method
To use su, type the command and then the target user’s password. To use sudo, prepend sudo to the desired command and enter the caller’s password.
4. Suitable Scenarios
Use su when you need to stay in another user’s environment for an extended period, such as running a series of commands as root.
Use sudo for occasional privileged actions like installing software, updating the system, or performing maintenance tasks.
5. Conclusion
Both su and sudo provide ways to gain elevated privileges on Linux, but they differ in authentication method, permission granularity, security implications, logging, and typical use cases. Choose the command that best matches your operational needs and security policies.
Linux Tech Enthusiast
Focused on sharing practical Linux technology content, covering Linux fundamentals, applications, tools, as well as databases, operating systems, network security, and other technical knowledge.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
