Add User to Sudoers or Sudo Group in AlmaLinux 8

To run commands to install packages and system update in Alamalinux using a non-root user, we need to make it a part of the sudo or wheel group. Here are the steps to do that.

Add User to Sudoers group on AlmaLinux 8

Step 1: Switch to Root user

First login as the root user protected with the password you have created while installing Almalinux. 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 root@server-ip-address.

 

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

If you haven’t already created a user or while installing the AlmaLinux, 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 AlmaLinux

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 AlmaLinux, 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 on AlmaLinux

 

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 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 way

If the above method didn’t work for you then we can directly add our user into the Sudoers file in AlmaLinux, 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 Comment

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