This brief tutorial shows you 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 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 runlevel 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 change 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 an acronym for superuser do or substitute user do. This command runs an elevated shell without a need to your account or your identity.
The sudo command allows user to run command with the root power described above. With the sudo command, you can practically do anything in Ubuntu Linux and its controlled by definitions in the /etc/sudoers file.
The sudo command also 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 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 use switch to other accounts on the system, but you’ll also need to know the password of the account you’re switching to.
The above command allow 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.
If you want to switch to a user on the system called john, you run the commands below:
To switch to to john 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
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 changing your identity.
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.