Skip to content
Follow
Ubuntu Linux

Working with Sudo and Su Commands in Ubuntu Linux

Richard
Written by
Richard
Mar 30, 2021 Updated Sep 15, 2026 2 min read
Enable Automatic Suspension in Ubuntu Linux Easily
Enable Automatic Suspension in Ubuntu Linux Easily

The sudo and su commands in Ubuntu Linux let you run administrative tasks or switch user accounts directly from your terminal. Ubuntu 8.04 LTS and newer versions rely on sudo to grant temporary superuser power for a single command, keeping your operating system safer than logging in as the root user all the time.

Advertisement

Typing sudo lets you install software or change system settings without putting your whole computer at risk. Running su switches your entire identity to another user until you type exit, which leaves room for costly mistakes if you type the wrong command.

⚡ Quick Answer

Sudo executes a single command as another user, typically root, while su switches your entire session to that user. Use sudo command for specific elevated tasks, and su – to log in as root for an extended session.

Advertisement

Sudo

Ubuntu’s sudo vs su Ubuntu comparison usually starts with sudo, a command that lets you run single administrative tasks with root powers without switching user accounts. You use sudo when you want to perform a quick system change safely while keeping your own user session active.

The `sudo` command includes safeguards against accidental mistakes. It prompts for confirmation before executing actions, encouraging you to think twice.

sudo apt update

su

Ubuntu’s sudo vs su Ubuntu choice often leads to su, a command that lets you switch completely to another user account, such as the root administrator. You type su when you need an ongoing shell session with full administrative rights rather than just running a single command.

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

Advertisement

Example:

su - 
⚠️WarningThe above command lets you switch to the root account.

However, you'll need to know the root password 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:

Advertisement

Running `su -` switches to another user's account, such as John's, and loads that user's environment settings and home directory path. This command has the same effect as logging into the system directly as the user you're switching to.

su - john

Understanding these differences helps you choose the right command for your task. Remember, `sudo` lets you run commands as another user without changing your own identity. `su`, on the other hand, allows you to switch to a user and adopt their identity.

Conclusion:

We've covered the main differences between sudo and su. If you spot any errors, please let us know using the form below.

Was this guide helpful?

100% of readers found this helpful (2 votes)

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard is a writer at Geek Rewind who turns complex IT tasks into clear, step-by-step guides. He draws on years of hands-on experience in system administration and enterprise IT operations, focusing on Windows, Linux and WordPress: the problems people actually run into, and the fixes that work. His server and WordPress guides come from systems he runs himself. Richard builds and maintains the platform behind Geek Rewind, from its Ubuntu servers and Nginx configuration to its custom WordPress plugins. Many new tutorials start with readers' questions, and he's always glad to answer them in the comments.

Advertisement

📚 Related Tutorials

How to Install Ruby on Ubuntu Linux
Ubuntu Linux How to Install Ruby on Ubuntu Linux
How to Install WildFly on Ubuntu Linux
Ubuntu Linux How to Install WildFly on Ubuntu Linux
How to Install OpenLiteSpeed on Ubuntu Linux
Ubuntu Linux How to Install OpenLiteSpeed on Ubuntu Linux
How to Install PHP on Ubuntu Linux
Ubuntu Linux How to Install PHP on Ubuntu Linux

2 Comments

Leave a Comment

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