The Linux sudo command is used to run a command as another user while logged in as another. Typically this is used to run a command that would need to be done while logged in as the root user, but done instead from a regular user account that is set up to do this. Such as installing or updating software by way of the apt command. However sudo can also be used to run a command as any user, assuming that permission is set up for the current user to do so.
There are alternatives to the use of the sudo command such as using the su command to switch to the root user, or any user assuming the password is known. Then I can do whatever I want from that user account, and then call su to switch back again.
One of the main things that I often used sudo for is to keep all the software up to date on Raspberry PI OS, or any Debian Linux based system, or any Linux System where apt is used for the package manager. If I try to do an apt update without using sudo while logged in as a non root user I will of course get errors.
Apt can not update the package lists because the regular user that I am logged into as does not have permission to do so. However this user is set up to be allowed to use sudo to do something like this. So if I do the same command, only starting to do so with the sudo command then the apt update command works just fine.
Looks like all the packages are up to date for now, but if there where updates I could install them by once again using the apt command with sudo. Only then I would do a full-upgrade rather than that of an update.
The process of setting up a new user will have to involve editing a file in the etc folder at /etc/sudoers. As you might suspect, yes in order to edit, or even view this file you must have root permission to do so to begin with. I might not get into every detail about setting up a new user to use sudo here, as it would seem that much of that might be a matter for another post, or maybe a future edit of this one. However there is still at least being aware of what files need to be edited in order to set, change, or in this case just view the current status of users and the use of sudo.
Before Even geting into how to set up a new user as a sudoer one might want to just check out the state of the files that store data that is used by sudo to know if a user has permission to do admin stuff or not. Once typical command that is used to read the state of text files and spit it out to the standard output would be the cat command. However if you do this without sudo, or without root permission by any means you will of course get a permission error.
If you are logged in as a user that is set up as a sudoer to begin with you can once agai use sudo with cat to read this restricted file.
Notice that the sudoers file says to use the visudo command to edit this file. After reading over the man page it would seem that it would be a good idea to use that command rather than editing this kind directly. Also you will notice that there is not just this file, but also a sudoers.d directory in the etc folder that will contain additional local files. So then it might be best to set up a new user by adding files there and leave this main sudoers file alone.
The Sudo command is then what I want to use when I have to do anything that requires root level permissions. This means anything that has to do with installing, and updating software, as well as any kind of admin task. There are a lot of little uses cases beyond using apt of course such as creating a new user, and also setting up a new user to also be allowed to use sudo and so forth.