Operations 6 min read

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.

Linux Tech Enthusiast
Linux Tech Enthusiast
Linux Tech Enthusiast
What’s the Difference Between Linux su and sudo Commands?

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

su

requires 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

su

grants 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

sudo

records 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.

Linuxprivilege escalationSudosu
Linux Tech Enthusiast
Written by

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.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.