Introduction
On traditional Unix and Unix-like systems, the first and only user that exists on a fresh install is named root. Using the root account, you log in and create secondary “normal” users. After that initial interaction, you’re expected to log in as a normal user.
Running your system as a normal user is a self-imposed limitation that protects you from silly mistakes. As a normal user, you can’t, for instance, delete the configuration file that defines your network interfaces or accidentally overwrite your list of users and groups. You can’t make those mistakes because, as a normal user, you don’t have permission to access those important files. Of course, as the literal owner of a system, you could always use the su command to become the superuser (root) and do whatever you want, but for everyday tasks you’re meant to use your normal account.
Using su worked well enough for a few decades, but then the sudo command came along.
To a longtime superuser, the sudo command might seem superfluous at first. In some ways, it feels very much like the su command. For instance, here’s the su command in action:
Example
$ su root
<enter passphrase>
# dnf install -y cowsay
And here’s sudo doing the same thing:
$ sudo dnf install-y cowsay
<enter passphrase>
The two interactions are nearly identical. Yet most distributions recommend using sudo instead of su, and most major distributions have eliminated the root account altogether. Is it a conspiracy to dumb down Linux?
Far from it, actually. In fact, sudo makes Linux more flexible and configurable than ever
Explanation
sudo (Super User DO) command in Linux is generally used as a prefix of some command that only superuser are allowed to run. If you prefix “sudo” with any command, it will run that command with elevated privileges or in other words allow a user with proper permissions to execute a command as another user, such as the superuser. This is the equivalent of “run as administrator” option in Windows. The option of sudo lets us have multiple administrators.
These users who can use the sudo command need to have an entry in the sudoers file located at “/etc/sudoers”. Remember that to edit or view the sudoers file you have to use sudo command. To edit the sudoers file it is recommended to use “visudo” command.
By default, sudo requires that users authenticate themselves with a password which is the user’s password, not the root password itself.
References:
https://www.geeksforgeeks.org/sudo-command-in-linux-with-examples/
Leave a comment