Before setting up the sudoers file, there is a chance that your system does not contain the sudoers. That’s why we will first explain the method to create the sudoers file and then configure it on Rocky Linux 9.
First, access the terminal as the root user. You can do it through the following command:
On the other side, if you are logging in from SSH, enter the root user and the IP address or the domain name of SSH:
Once you access the terminal as the root user, it is time to open the sudoers file:
Now, you can setup and configure the sudoers file. Here, you can add the users. Let’s take an example of adding a user in the sudoers file. First, scroll through the lines until you see the following line:
Here, you can add one more user, but the sudo privileges depend on the requirements such as:
You can write the following line to grant access to the group:
To grant access to the specific commands, you can try the following line:
Once you are done, save and exit the file. Now, run the following command to validate the changes in the file:
Finally, you can verify the changes by executing the following command and replace the username with the exact username that you added:
This is how you can easily setup and configure the sudoers file on Rocky Linux 9 to add new users to the device. We used the simple method to configure the sudoers file to add the users, but you can use the various commands to add the users directly. Please carefully modify the sudoers file because an incorrect modification can generate some system vulnerabilities.