Before we begin talking about how to create a New Sudo-enabled User on Rocky Linux 8, let's briefly understand – What is sudo?
sudo command provides a method for granting regular users the administrator privileges that are often only granted to the root account. You won't need to change the
/etc/sudoers file on your server in order to follow the instructions in this guide to create a new user with
sudo access on Rocky Linux 8.
In this tutorial, you will create a New Sudo-enabled User on Rocky Linux 8. We will also address a few FAQs on how to create a New Sudo-enabled User on Rocky Linux 8.
Step 1 — Logging Into Your Server
SSH as the root user into your server:
Change the above
your_server_ip_address to your server's IP address or hostname.
Step 2 — A New User is Added to the System
To add a new user to your system, issue the command
Make sure you substitute the desired username for
To change the new user's password, use the
Do not forget to substitute the newly created user for
sammy. Two new password requests will be sent to you:
Changing password for user sammy.
Retype new password:
passwd: all authentication tokens updated successfully.
Step 3 — Including the User in the Wheel Group
To include the user in the wheel group, issue the
usermod -aG wheel sammy
Again, be sure to switch
sammy with the username you want to have
sudo access to. On Rocky Linux, all members of the wheel group come pre-configured with full
Step 4 — Testing
su command to switch from the root user to the new user account before testing the new
su - sammy
Check that you can use
sudo as the new user by adding
sudo before the command you wish to run with superuser privileges:
You can, for instance, list the contents of the
/root directory, which is usually only available to the root user:
sudo ls -la /root
You will be asked for that user's account password the first time you use
sudo in a session. To proceed, enter the password:
[sudo] password for sammy:
The command you used with
sudo will run with root privileges if your user is in the correct group, and you supplied the correct password.
FAQs to Create a New Sudo-enabled User on Rocky Linux 8
How can I set a password for the newly created user?
After creating the user, you can set a password using the
passwd command, like
sudo passwd myuser. You will be prompted to enter and confirm the new password.
What is the command to add the new user to the sudoers group?
To add a user to the sudoers group, use the
usermod command with the
-aG sudo option, like
sudo usermod -aG sudo myuser.
Can I create a new user and grant sudo privileges simultaneously?
Yes, you can create a new user and grant sudo privileges in one command. Use
adduser instead of
sudo adduser myuser sudo.
How can I verify if a user has sudo privileges?
You can use the
sudo -l command to check the sudo privileges of a user. It will display the user's allowed sudo commands, if any.
What should I do if the newly created user is unable to use sudo?
Ensure the user is added to the sudoers group correctly. You can verify this by checking the
sudo group membership using the
Can I remove sudo privileges from a user?
Yes, you can remove sudo privileges from a user by removing them from the sudoers group. Use the
deluser command, like
sudo deluser myuser sudo.
What is the recommended way to create a user and manage sudo on Rocky Linux?
It is generally recommended to use the
adduser command to create a user and include them in the
sudo group using the
usermod command, ensuring both steps are successful.
In order to grant
sudo access, you created a new user account in this quick-start tutorial and added it to the wheel group.
If you have any queries or doubts, please leave them in the comment below. We'll be happy to address them.