Working with Sudo and Su Commands in Ubuntu Linux
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.
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.
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 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.
Example:
su -
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.
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)
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.
[…] Another way to access the PostgreSQL prompt without switching users is to use the sudo command. […]
[…] What is the sudo or su command on Ubuntu Linux […]