Grant sudo access to a user

In RHEL, you can allow non-root users to enter administrative commands by granting them sudo access. This ensures that users can perform privileged tasks securely without requiring the root user’s password.

Before you begin

  • You have root access to the system.

About this task

When users need to perform an administrative command, they can precede that command with sudo. If the user has authorization for the command, the command is executed as if they were root.

Be aware of the following limitations:

  • Only users listed in the /etc/sudoers configuration file can use the sudo command.
  • The command is executed in the shell of the user, not in the root shell. However, there are some exceptions such as when full sudo privileges are granted to any user. In such cases, users can switch to and run the commands in root shell. For example:
  • sudo -i
  • sudo su -

Procedure

  1. As root, open the /etc/sudoers file.
    # visudo

    The /etc/sudoers file defines the policies applied by the sudo command.

  2. In the /etc/sudoers file, find the lines that grant sudo access to users in the administrative wheel group.
    ## Allows people in group wheel to run all commands
    %wheel        ALL=(ALL)       ALL
  3. Ensure the line that starts with %wheel is not commented out with the number sign (#).
  4. Save any changes, and exit the editor.
  5. Add users you want to grant sudo access to into the administrative wheel group.
    # usermod --append -G wheel <username>

    Replace <username> with the name of the user.

Results

  • Verify that the user is in the administrative wheel group:
    # id <username>
    uid=5000(<username>) gid=5000(<username>) groups=5000(<username>),10(wheel)