How to Add Sudo User on RHEL / Rocky Linux / Alma Linux

In this tutorial, we will cover how to add a sudo user on RHEL, Rocky Linux and Alma Linux.

Sudo is a powerful and widely used command-line tool that allows regular users to perform administrative tasks on a Linux system. By default, most Linux distributions have a root user account that has full administrative privileges. However, logging in as the root user can be dangerous, as it can lead to unintended modifications to the system, and compromise the overall security of the system.

One way to mitigate these risks is to create a sudo user. A sudo user is a regular user who has been granted permission to perform administrative tasks on a Linux system using the sudo command.

In Linux distros like RHEL, CentOS, Rocky Linux & Alma Linux, a wheel group is created automatically during the installation. When we add any regular to wheel then that user will have administrative rights.

Step 1) Access Your System with Root User

To create a sudo user, you will need to log in as the root user on your Linux system. Open the terminal window.

Alternate way: If your linux server is on network, then ssh it is using root user credentials.

# ssh root@<Server-IP-Address>

You will be prompted to enter the root user password. After entering the correct password, you will be logged in as the root user.

Step 2: Create a New Regular User & assign Sudo Privileges

Now that you are logged in as the root user, you can create a new user account. While creating a new user, one assign sudo privileges to it using following useradd command,

# useradd -G wheel -s /bin/bash <username>

Replace <username> with the name of the new user you want to create. This command creates a new user account with a home directory and a default shell of /bin/bash.

Example

# useradd -G wheel -s /bin/bash opsadm

After creating the user, you need to set a password for the user. To set a password for the new user, enter the following command:

# passwd <username>
Or
# echo "R#D$GT@1#" | passwd <username> --stdin

Replace <username> with the name of the new user you just created. Enter a new password for the user. Make sure to choose a strong and secure password.

# passwd opsadm

Output of above commands,

Add-Regular-User-RHEL-RockyLinux-AlmaLinux

Run following id command to verify that whether user is part of wheel group or not.

# id <username>

# id opsadm
uid=1001(opsadm) gid=1001(opsadm) groups=1001(opsadm),10(wheel)
#

Perfect, output above confirms that user is a part of wheel group.

Step 3: Grant Sudo Privileges to existing Users

To grant sudo privileges to the existing users, you need to add the user to the wheel group. To add the user to the wheel group, enter the following usermod command:

# usermod -aG wheel <username>

Replace <username> with the name of the new user you just created. This command adds the existing user to the wheel group, which allows the user to run commands with administrative privileges using the sudo command.

Let’s assume, we want eric user to be added to wheel group then run

# usermod -aG wheel eric
# id eric
uid=1002(eric) gid=1002(eric) groups=1002(eric),10(wheel)
#

Step 4: Verify Sudo Privileges

To verify that the new user has sudo privileges, you can try running a command that requires administrative privileges using the sudo command. Login to your system as regular user and try installing a package ‘net-tools’

For example, you can try updating the system using the following command:

$ sudo dnf install net-tools

If the new user has sudo privileges, it will be prompted to enter their password before the command is executed.

Sudo-User-Testing-RHEL-RockyLinux-AlmaLinux

Conclusion

Creating a sudo user is an essential step in securing your Linux system. By following the steps outlined in this tutorial, you can create a new user with sudo privileges on your RHEL, Rocky Linux or Alma Linux system. Remember to choose a strong and secure password for the new user, and always use sudo responsibly to avoid unintended modifications to the system.

Also Read: How to Create Sudo User on Ubuntu / Debian Linux

1 thought on “How to Add Sudo User on RHEL / Rocky Linux / Alma Linux”

Leave a Comment

two × 1 =