How To Add User to Sudoers or Sudo Group on Rocky Linux 8

After installing the Rocky Linux, your non-root user wouldn’t be a part of sudo group,  thus you won’t be able to install software and run the update command. For that, we manually need to add our user to sudo means Super User Do group. The steps are given here will also work for Almalinux and CentOS 8.

What do we need to perform given steps in this tutorial?

  • A root user access.
  • Rocky Linux

What we are solving here – “your user is not in the sudoers file. This incident will be reported.”

Add User to Sudoers group on Rocky Linux 8

Step 1: Switch to Root user

First login as the root user protected with the password you have created while installing Rocky. Hence, on your command terminal type:

su

Enter the password.

cd

If you are accessing the server on SSH, then directly connect it with the root user, the command will be like this-
ssh [email protected].

Switch to Root user

 

Step 2: Create a non-root user (optional) on Rocky Linux

If you haven’t already created a user or while installing the Rocky Linux, then you can use the command given here to create a new user.

adduser User

After that assign a password to your newly created user. The system will ask to enter a new password for the user two times.

passwd user

Replace the User with the name you want to give to your new user.

 

Step 3: Enable Wheel Group access for all users on Rocky Linux

The wheel is the group under which a user will have sudo access to run all commands on the system just like the root user. However, on Rocky Linux, by default, it will be enabled, still, confirm it by following commands.

dnf install nano
nano /etc/sudoers

Scroll down, until you find a line given below:

# %wheel ALL=(ALL) ALL

Once you find the line remove the given in the front of that.

Save the file by pressing Ctrl+X, type Y, and hit the Enter key.

Enable Wheel group for users onm Rocky Linux

 

Step 4: Add non-root user to the sudo (Wheel) group

Now, use the usermod command to add your existing user to the Wheel group, this will give it access to run the command.

usermod –aG wheel your-user

Replace your-user with the one, you want to add to the Wheel group.

 

Step 5: Switch back to a non-root user

Switch back to the user that is not the root but you have made it a part of the sudo group using the command given above-

su your-user
cd

Now, you will be able to run commands using sudo with your existing user.

 

Alternate method

If the above method didn’t work for you then we can directly add our user into the  Sudoers file in Rocky Linux, by following the given commands:

nano /etc/sudoers

Find

## Allow root to run any commands anywhere

root ALL=(ALL) ALL

Right after it, add:

your-user ALL=(ALL) ALL

Replace your-user with the username that you want to add to sudo group.
group.

Save the file Ctrl+X, Y, and hit the Enter key.

 

 

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.