Skip to content
Follow
Ubuntu Linux

Working with Sudo and Su Commands in Ubuntu Linux

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

The sudo command lets you run specific commands with special administrator rights on Ubuntu Linux, while the su command lets you switch your entire session to another user, like the main administrator.

Understanding this difference is important for managing your Ubuntu system safely. sudo gives you temporary, single-command access to do things you normally can’t, like when you install new software.

On the other hand, su completely changes who you are in the terminal, letting you do anything as that user until you type exit. Using the main administrator account directly can be dangerous, as one wrong step could break your system. sudo, which became common around Ubuntu 8.04 LTS, offers a safer way by only giving you the power you need for just one task.

⚡ 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. The `sudo` command is controlled by definitions in the `/etc/sudoers` file, which contains rules for user privileges.

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 - 

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:

The `su -` command lets you switch to another user's account, such as John's, and load that user's environment variables, including their 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 Change Default Distro in Windows Subsystem for Linux
Windows How to Change Default Distro in Windows Subsystem for Linux
How to Set Up Environment Variables in Windows 11
Windows How to Set Up Environment Variables in Windows 11

2 Comments

Leave a Comment

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