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 a chance to confirm that you want to execute certain 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 a chance to confirm if you’re sure 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 an elevated 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.

su

su on the other hand is an acronym for switch user or substitute user. Most often the su command is used to switch to the root user but 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 password of the account you’re switching to. Example: 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: 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. 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.