How to Add a User to Sudoers in AlmaLinux or Rocky Linux
What is sudoers in Linux?
Have you ever wondered why it takes “sudo” or “su” to make system-wide changes in a Linux terminal? Su means “super user,” while sudo means “super user do.” With this command, you’re requesting root access and the status of a super user. If your name is not on the list, Linux checks a specific file to see if you are authorized to be given root access, much like a VIP CLUB. While you can still obtain root capabilities, you must log in as root to do so. This is not a very secure course of action. Reason: If you have root access, your system’s doors are wide open, making it vulnerable. The commands “sudo” and “su” permit you to run a specific program that you specify.
That individual file already has the maintenance user account configuration in certain distributions. You type:
And enter your user account’s password, or
And then, type the command after entering the root password. I’ve come to understand that not all distributions support this simple process, and you might need to manually add your username to the sudoers file. We just took the VIP list from the guard dozing off, and we’ll teach you how to add your name.
Linux and Unix system administrators can assign user rights using the sudoers file. As a result, the administrator can manage who does what. Keep in mind that Linux was created with security in mind. Linux validates your username against the sudoers file when you attempt to execute a command that needs root privileges. When you enter the command sudo, this occurs. You cannot run the command or program as that user if it finds that your username is not on the list.
You must use the command “su -l” to log in as “root.” It should log in normally if “-l” is used. The su command’s default user is root. After entering the root account’s password, a shell prompt will appear where you can issue any order as root. Once more, this is unsafe. If you log in as root, the system is vulnerable. It is best to grant non-root users access so they can run desired commands or programs. Your username needs to be in the sudoers file, though.
The sudoers file is located in “/etc/sudoers.” To view a list of everything in the directory, type “ls -l /etc/”. A lengthy and thorough listing is produced by adding -l to the end of ls.
File for Sudoers
Here is how the Linux sudoers file is organized. Depending on your system, your sudoers file could be different, but it should still be the same.
Several intriguing Linux-based OS distributions can be found in the Redhat Enterprise Linux (RHEL) ecosystem. The OS duo of Rocky Linux and AlmaLinux is a promising substitute for the ceased CentOS distribution.
Due to their performance footprints, RHEL 8, AlmaLinux, and Rocky Linux systems are increasingly sought by Linux users.
There are two types of primary users in an operating system environment: root (Sudoer) users and non-root users. In addition to managing the OS’s apps, processes, and configurations, root users have complete authority over the operating system environment and can create new users. Users without root have just a little contact with an operating system.
You will eventually need to grant other non-root users more OS rights and execution authority as the root user on your Linux system. These regular OS users must advance to Sudo users for this step.
Before continuing with the article instructions, ensure your computer has root user access capabilities.
Creating a New Sudo/Sudoer User in Linux
The term “Sudo” is an abbreviation that can refer to either “superuser do” or “substitute user do.” Existing Sudoer users’ security policy related to their warranted privileges is stored in the file system’s directory path /etc/sudoers.
Executing the following command will result in the creation of a brand-new user from scratch.
sudo adduser m1
The command above will create m1 as a non-root user.
The login password for this new user must then be assigned.
sudo passwd m1
Option 1: Add User to Sudo Wheel Group
Sudo access and privileges are only available to wheel group members. We will use the usermod command to do the following to add user m1 to the wheel group.
sudo usermod -aG wheel m1
With the mentioned command, “m1” is now a Sudoer user.
Option 2: Editing /etc/sudoers File
This file contains a list of every user on your network, along with their customizable access and privileges. The following instructions will show you how to change this file to turn our newly formed user into a sudoer user. First, launch your chosen command-line editor and open the file.
sudo nano /etc/sudoers file
To make m1 a sudoer user, we will modify the bottom of this file.
When running sudo-related terminal commands, the NOPASSWD part of the following entry will exclude the “m1″r user from having to follow any password authentication mechanism.
Testing Sudoer User Access in Linux
We must verify that we did create a Sudoer account. The following commands can be used to run the first Sudoer user test.
You can use the whoami command before changing to the new user’s home directory.
We are dealing with the root user, as the command output indicates. If nothing else, showing the items under /root should demonstrate that we are dealing with a root/sudo user. Under a non-root user profile, the contents of the /root path cannot be seen.
sudo ls -la /root
Users with sudo/sudoer permission can access Linux OS features unavailable to non-sudo users. This user has additional authority in the OS role they were given.
The guide taught you how to add sudo permissions and users to your Rocky Linux operating system. Overall, all supported versions of Rocky Linux should be compatible with this guide, and it is advised to provide permissions to only trusted users because they will have access to sensitive files thanks to the sudo permit.