Skip to content
Follow
Ubuntu Linux

Working with Sudo and Su Commands in Ubuntu Linux

Richard
Written by
Richard
Mar 30, 2021 Updated Aug 14, 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 tasks with administrator rights or switch your entire terminal session to another user. Ubuntu 8.04 LTS and later versions rely heavily on sudo to keep your system safe by granting temporary power for just one task at a time.

Running the sudo command gives you single-command access to install software or change settings without putting your whole system at risk. Typing su switches your identity entirely until you type exit, which can break things if you make a mistake.

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

Sudo

Ubuntu’s `sudo` command grants administrator powers, letting you run commands that typically require root access without logging out. This control over who can use `sudo` and for what purpose makes system management safer. Effectively, `sudo` lets you wield root power for specific tasks. Rules for user privileges live in the `/etc/sudoers` file, which controls how `sudo` behaves.

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

🐧Bash / Shell
sudo apt update

su

The `su` command in Ubuntu lets you switch to another user account, like the main administrator (root). To switch accounts, you need the password for the account you want to use. For example, typing `su -` lets you become the root user for a little while, giving you temporary admin control.

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.

Example:

💻Code
su - 
⚠️Warning
The 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:

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.

💻Code
su - john

Hopefully, this clarifies the differences between these two commands. 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?

Was this helpful?
Richard

About the Author

Richard

Tech Writer, IT Professional

Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips 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.

📚 Related Tutorials

How to Install Yarn on Ubuntu Linux?
Ubuntu Linux How to Install Yarn on Ubuntu Linux?
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

2 Comments

Leave a Comment

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