Working with Sudo and Su Commands in Ubuntu Linux

The tutorial differentiates between the ‘sudo’ and ‘su’ commands in Ubuntu Linux and their application. ‘Sudo’, standing for superuser do or substitute user do, runs a high shell without the need for user identity, allowing commands to be run with root power. ‘Su’, or switch user, lets users change their current account to any account…

This brief tutorial shows the differences between the sudo and su commands when working with Ubuntu Linux.

Most students and new users are confused about the sudo and su commands and how to use them in Linux. If you want to understand the differences between both, continue reading below.

The root or administrator account in Linux gives you a lot of power. The root user can change the run level of a system, change and remove any file, remove software, add and remove accounts, and lots more.

You can practically do anything in Linux with the root account.

Using the root account to manage your system can be dangerous. In most cases, you won’t get to confirm that you want to execute specific tasks before executing, even if the commands would damage the system.

For example, when you use the root account and run the command rm -r *, you may not get to confirm if you want to run that.

You can see how dangerous this can be and how it may render a system inoperable when mistakes are made.

To get to know the differences between sudo and su, continue below:

Sudo

Sudo is an acronym for superuser do or substitute user do. This command runs a high shell without a need for your account or your identity.

The sudo command allows the user to run the command with the root power described above. With the sudo command, you can practically do anything in Ubuntu Linux, and it’s controlled by definitions in the /etc/sudoers file.

The sudo command is also a way to provide some safeguards and protections before making mistakes. It makes you think twice with confirmation prompts before actions are executed.

sudo apt update

su

su, on the other hand, is an acronym for switch user or substitute user. The su command is often used to switch to the root user, but it can be any account on the system.

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

Example:

su - 

The above command allows you to switch to the root account. However, you’ll need to know the root password before being able 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:

su john

To switch to John’s account, including using John’s account path and environment variables, use the (-) switch. The switch has the same effect as logging into the system directly as the user you’re switching to.

su - john

That’s it!

This should help clear some things up between the two commands. Again, 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:

This post described some of the differences between sudo and su commands. If you find any error above, please use the form below to report.

Richard Avatar

Comments

Leave a Reply

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