Ubuntu Linux

Working with Sudo and Su Commands in Ubuntu Linux

Working with Sudo and Su Commands in Ubuntu Linux
Richard
Written byRichardTech Writer, IT Professional
Mar 30, 2021 Updated Mar 18, 2026 4 min read Reviewed Mar 18, 2026

This brief tutorial shows the differences between the sudo and su commands when working with Ubuntu Linux.

Most students and new users are confused about the sudo and su commands and how to use them in Linux. If you want to understand the differences between both, continue reading below.

The root or administrator account in Linux gives you a lot of power. The root user can change the run level of a system, change and remove any file, remove software, add and remove accounts, and lots more.

You can practically do anything in Linux with the root account.

Using the root account to manage your system can be dangerous. In most cases, you won’t get to confirm that you want to execute specific tasks before executing, even if the commands would damage the system.

For example, when you use the root account and run the command rm -r *, you may not get to confirm if you want to run that.

You can see how dangerous this can be and how it may render a system inoperable when mistakes are made.

To get to know the differences between sudo and su, continue below:

Sudo

Sudo is an acronym for superuser do or substitute user do. This command runs a high shell without a need for your account or your identity.

The sudo command allows the user to run the command with the root power described above. With the sudo command, you can practically do anything in Ubuntu Linux, and it’s controlled by definitions in the /etc/sudoers file.

The sudo command is also a way to provide some safeguards and protections before making mistakes. It makes you think twice with confirmation prompts before actions are executed.

🐧Bash / Shell
sudo apt update

su

su, on the other hand, is an acronym for switch user or substitute user. The su command is often used to switch to the root user, but it can be any account on the system.

The su command will let us switch to other accounts on the system, but you’ll also need to know the account password you’re switching to.

Example:

💻Code
su - 

The above command allows you to switch to the root account. However, you’ll need to know the root password before being able to run the root user shell and environment.

Another example:

If you want to switch to a user on the system called john, you run the commands below:

💻Code
su john

To switch to John’s account, including using John’s account path and environment variables, use the (-) switch. The switch has the same effect as logging into the system directly as the user you’re switching to.

💻Code
su - john

That’s it!

This should help clear some things up between the two commands. Again, sudo lets you run commands as another user without changing your identity.

Su allows you to switch to a user and change your identity.

Conclusion:

This post described some of the differences between sudo and su commands. If you find any error above, please use the form below to report.

Frequently Asked Questions

What is the difference between sudo and su commands in Ubuntu?

The sudo command allows users to run commands with root privileges without switching accounts, while the su command switches the user to another account, requiring the password of the target account.

When should I use sudo instead of su?

You should use sudo when you want to execute a single command with elevated privileges without changing your user context, making it safer for routine tasks.

Can I use sudo to switch to another user?

Yes, you can use sudo to switch to another user by using the command 'sudo -u username', which allows you to run commands as that user without needing their password.

What are the risks of using the root account with su?

Using the root account with su can be risky because it grants full control over the system without confirmation prompts, increasing the chance of executing harmful commands by mistake.

How do I switch back to my original user after using su?

To switch back to your original user after using su, simply type 'exit' or press Ctrl+D in the terminal, which will log you out of the current user session.

Was this guide helpful?

Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, the owner and lead writer at Geek Rewind, is a tech enthusiast passionate about simplifying complex IT topics. His years of hands-on experience in system administration and enterprise IT operations have honed his ability to provide practical insights and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.

2452 articles → Twitter

📚 Related Tutorials

How to Record Videos on Ubuntu with Cheese
Ubuntu Linux How to Record Videos on Ubuntu with Cheese
How to Install Postfix on Ubuntu 24.04
Ubuntu Linux How to Install Postfix on Ubuntu 24.04
How to Locate Your Mouse Pointer in Ubuntu Linux
Ubuntu Linux How to Locate Your Mouse Pointer in Ubuntu Linux
Disable Nginx Directory Listing on Ubuntu 24.04
Ubuntu Linux Disable Nginx Directory Listing on Ubuntu 24.04

2 responses to “Working with Sudo and Su Commands in Ubuntu Linux”

Leave a Reply

Your email address will not be published. Required fields are marked *