Skip to content
Follow
Ubuntu Linux

Working with Sudo and Su Commands in Ubuntu Linux

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

The sudo command lets you execute specific commands with elevated privileges, while the su command switches your entire Linux session to another user, typically root.

This distinction is vital for managing your Ubuntu system securely. Sudo allows temporary, command-specific elevated access, like when you run apt-get update.

In contrast, su opens a new shell session logged in as the target user, meaning all commands run with that user’s permissions until you exit the session.

Directly using the root account can be dangerous; a mistake could easily damage your system. Sudo, first widely adopted around Ubuntu 8.04 LTS, provides a safer way to perform administrative tasks by granting temporary root access only for the command you execute.

⚡ 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

The sudo command in Ubuntu lets you run other commands with special admin powers, like being the superuser. It’s a way to do things that normally require root access without logging out and back in. You control who can use sudo and what they can do through a special file.

With `sudo`, you can run commands with root power, as described above. This command lets you do practically anything in Ubuntu Linux, and it’s controlled by definitions in the /etc/sudoers file.

The `sudo` command also provides safeguards before you make mistakes. It prompts you for confirmation before executing actions, making you think twice.

🐧Bash / Shell
sudo apt update

su

The su command in Ubuntu lets you switch to a different user account, including the main administrator (root) account. To switch, you’ll need to know the password for the account you want to switch to. For example, typing `su -` lets you become the root user.

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:

💻Code
su john

To switch to John’s account and load his environment variables (like his home directory path), use the switch. This 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 up some differences between the two commands. Remember, `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:

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 *