Why sudo is so important in Linux and how to use it

When I first started using Linux things were exponentially more complicated. The distributions were far less mature, but they also required the use of a specific system account to do specific things. That account was root, giving you unlimited power over your operating system.

To demonstrate the power of root, you could always trick unsuspecting users into using the su command to tell them to switch to the root user, and then have them run the following command:

rm -rf /

ZDNet recommends

The best Linux Foundation courses

The best Linux Foundation courses

Fancy a good tech job? Then you must be familiar with Linux and open source software. One of the best ways to learn is through a Linux Foundation course.

The rm command is used to delete files and folders. In conjunction with r (recursive) and f (force), you would delete everything from the root (/) folder, rendering your system unusable.

Back then, any command that required administrator privileges was run as the root user. To do this, you had to either switch to the root user (using the su command) or log in as the root user. Both options were eventually considered a security issue. Why? Once you logged in as root and exited your system, anyone could do with it what they wanted. The same applies if you switch to the root user and leave a terminal window open.

Of course, it’s much more complicated than that. Accessing the root user meant that if a hacker gained access to your system, they could switch to the root user and wreak havoc on the computer.

Finally it was decided to give something. Out of this need, sudo was born. Sudo stands for “superuser do” and gives a regular user (one who belongs to the admin group) access to administrator-like powers. This solved two problems:

  • The root user could be disabled (therefore not so easy to use).
  • Only users in the Admin group (more on that later) could perform administrative tasks.

This was a significant advance for Linux that not only strengthened the security of the system but also made it easier for users.

With sudo, users no longer had to switch to the root user or log in to that account to run administrative commands (e.g. installing software). Users could perform these administrative activities via sudo with the same effect as if they were being performed by the root user account. In addition, it offered better control over who could do what on a given system. When attempting to run a command that required administrative privileges, a user only had to enter their user password (aka sudo password) and the command ran without issue (if executed properly).

For example, instead of first suing to the root user and then issuing the update/upgrade commands on an Ubuntu-based distribution, you could simply issue the commands:

sudo apt-get update
sudo apt-get upgrade -y

Running apt-get via sudo gives the user temporary administrative privileges and allows them to run these commands successfully.

What about users who are not in the admin group?

Regarding the basics of using sudo, any user you want to grant access to that particular power must be a member of the admin group for that distribution. For example, on Ubuntu-based distributions, this group is called sudo, while on Red Hat-based distributions, this group is called wheel.

If you have a user who isn’t a member of the admin group, when they try to run a command with sudo they’ll see something like this:

olivia is not in the sudoers file.  This incident will be reported.

how to fix this You add them to the admin group. So for an Ubuntu based distribution the command to add a user to the admin group is:

sudo usermod -aG sudo USER

Where USER is the relevant username.

On a Red Hat based distribution (like Fedora) this command would be:

sudo usermod -aG wheel USER

Where USER is the relevant username.

After running the command, the user would then have to either log out and back in, or alert the system to the changes with the command:

newgrp

Once a user has been added to the Administrators group, they can use sudo to run commands that require administrative privileges.

Sudo has not only made Linux more secure, but also more user-friendly. You no longer need to switch to the root user account (or log in) to avoid a number of serious security issues, and you can manage user access to administrative tasks. Although this is a very basic introduction to sudo (we’ll go into more depth later), you should now have a better idea of ​​what it is and how to use it.

About Willie Ash

Check Also

Ubuntu running on a Google Nest Hub, wait a minute?

I just discovered a story about Ubuntu running on a Google Nest Hub (2nd gen). …