The sudo command allows regular users to execute commands with administrative/root privileges. By adding any user to predefined sudo group wheel will grant root privileges to execute any command as root user. Any attempt to use the sudo command for the non-sudo user will result in:
user is not in the sudoers file.  This incident will be reported.
In this tutorial you will learn:
  • How to create sudo user on RHEL 8 / CentOS 8 system.
  • How to add existing user to sudoers.
User is not in the sudoers file error message on RHEL 8 / CentOS 8 Linux
User is not in the sudoers file error message on RHEL 8 / CentOS 8 Linux.

Software Requirements and Conventions Used

Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System RHEL 8 / CentOS 8
Software N/A
Other Privileged access to your Linux system as root or via the sudo command.
Conventions # - requires given linux commands to be executed with root privileges either directly as a root user or by use of sudo command
$ - requires given linux commands to be executed as a regular non-privileged user

RHEL 8 / CentOS 8 add user to sudoers step by step instructions

In this section we will add sudo privileges to an existing user eg. linuxconfig.

  1. Gain root command line access:

    $$$ Looking for LINUX ADMINISTRATOR ! $$$

    BLUE SKY STUDIOS are looking for Linux Administrator to maintain and support the Studio's 450+ production Linux workstations, including daily interactions with the Studio’s digital animation artists.
    LOCATION: Greenwich, Connecticut, USA

    APPLY NOW

    $ su
    
  2. Add user to the wheel group. In this example we will create new sudo user from an existing user linuxconfig:
    # useradd -G wheel linuxconfig
    
    WARNING
    Giving the power to the user to execute any command with root privileges might NOT be the smartest move. You may try to limit the user power by allowing only system usage by un-commenting the:
    %sys ALL = NETWORKING, SOFTWARE, SERVICES, STORAGE, DELEGATING, PROCESSES, LOCATE, DRIVERS
    
    line within the /etc/sudoers file and including the user to the sys group instead of the wheel group. You may also explore other preconfigured options within /etc/sudoers to further limit the user's power to avoid possible unintentional or intentional accidents.
  3. Re-login we the new sudo user to apply the new settings:
    # su linuxconfig
    
  4. Test sudo permissions:
    $ sudo whoami
    root
    
    If all went well the above command should produce the root output.
  5. Add existing user to sudoers file on Redhat 8 Linux
    Add existing user to sudoers file on Redhat 8 Linux.


RHEL 8 / CentOS 8 create a new sudo user step by step instructions

In this section we will be creating a new sudo user account.
  1. Gain root command line access:
    $ su
    
  2. Use the useradd command to create a new user eg. foobar and add user to the wheel group.
    # useradd -G wheel foobar
    
  3. Set password to new foobar:
    # passwd foobar
    
  4. Re-login we the new sudo user to apply the new settings:
    # su foobar
    
  5. Test sudo permissions:
    $ sudo whoami
    root
    
ARE YOU LOOKING FOR A LINUX JOB?
Submit your RESUME, create a JOB ALERT or subscribe to RSS feed on LinuxCareers.com.
LINUX CAREER NEWSLETTER
Subscribe to NEWSLETTER and receive latest news, jobs, career advice and tutorials.
DO YOU NEED ADDITIONAL HELP?
Get extra help by visiting our LINUX FORUM or simply use comments below.