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 root@server-ip-address
.
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.
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.
Hello,
Thanks for your guide. Interesting.
I would like to say that you start a root shell by “su”.
At the end, when you want to switch back to the initial user, you use su again in the way of “su user”. Technically, you are not going back. You are just opening a new shell for the user “user” so you have the first shell, the second for su and a third for su user.
A better approach is, instead of using “su user”, typing exit and Enter or just Ctrl+d.
+++++++++++++++++++++
user@system:~$ ps
PID TTY TIME CMD
55259 pts/0 00:00:00 bash
55432 pts/0 00:00:00 ps
user@system:~$ su
Password:
root@system:/home/user# ps
PID TTY TIME CMD
55435 pts/0 00:00:00 su
55437 pts/0 00:00:00 bash
55440 pts/0 00:00:00 ps
root@system:/home/user# su user
user@system:~$ ps
PID TTY TIME CMD
55259 pts/0 00:00:00 bash
55444 pts/0 00:00:00 bash
55451 pts/0 00:00:00 ps
user@system:~$ exit
exit
root@system:/home/user# exit
exit
user@system:~$ ps
PID TTY TIME CMD
55259 pts/0 00:00:00 bash
55484 pts/0 00:00:00 ps
+++++++++++++++++++++
Regards.