Rocky Linux

How to Setup and Configure the Sudoers File on Rocky Linux 9

The sudoers file contains information about all those users or groups that have administrative privileges. In all Linux distros, the sudoers file are the essential component of the system because it allows the users to execute the commands as the root. Therefore, setting up a sudoers file is necessary to maintain security, flexibility, accountability, centralized administration, and privilege management.By setting up the sudoers file, the system admins enforce security and control on the administrative access. Linux distros like Rocky Linux 9 do not have a simple way to configure the sudoers files, and the users sometimes get errors. If you want to learn how to set up and configure the sudoers file on Rocky Linux 9, this guide is for you.

How to Setup and Configure the Sudoers File on Rocky Linux 9

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:

ssh root_user@server_ip


ssh root_user@domain

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:

root ALL=(ALL) ALL

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:

Group_Name ALL=(ALL) ALL

To grant access to the specific commands, you can try the following line:

john ALL=(ALL) /bin/ls, /usr/bin/dnf

Once you are done, save and exit the file. Now, run the following command to validate the changes in the file:

visudo -c

Finally, you can verify the changes by executing the following command and replace the username with the exact username that you added:

sudo -l -U username


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.

About the author

Prateek Jangid

A passionate Linux user for personal and professional reasons, always exploring what is new in the world of Linux and sharing with my readers.