How to fix: user not in sudoers file error

The purpose of this tutorial is to show how to fix the RHEL7 User Not In Sudoers File Error on all major Linux distributions. When trying to execute Linux commands with root privileges via the sudo command, you will receive an error message if the current user is not in the sudoers file. This is a security feature on Linux systems to stop ordinary users from esclating their commands to administrator privileges.

The remedy for this error is to add the user to the sudo group on DEB based systems or to the wheel group on RPM based systems. In this tutorial, you will see how to fix this error message and add a user to the respective group.

In this tutorial you will learn:

  • How to enable sudo usage on DEB and RPM based Linux distributions
  • How to resolve the RHEL7 User Not In Sudoers File Error
How to fix: user is not in the sudoers file error
How to fix: user is not in the sudoers file error
Software Requirements and Linux Command Line Conventions
Category Requirements, Conventions or Software Version Used
System Any DEB or RPM based Linux system
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

How to fix: RHEL7 User Not In Sudoers File Error step by step instructions



DID YOU KNOW?
You can always access the root account by simply logging in with the su command. It is not strictly necessary to use sudo or enable this functionality if you do not want to.

The error message looks like this:

$ sudo -i
[sudo] password for linuxconfig: 
linuxconfig is not in the sudoers file.  This incident will be reported.

Many users may see the RHEL7 User Not In Sudoers File Error on Red Hat Enterprise Linux or another major Linux distro.

In order to fix the error, all we need to do is add our user to the correct group. The correct group will depend on what distro you’re using. For RPM based distros, such as Red Hat, CentOS, Fedora, AlmaLinux, Rocky Linux, etc, this will be the wheel group. For DEB based distros, such as Debian, Ubuntu, Linux Mint, etc, this will be the sudo group.

Follow the step by step instructions below to add your user to the correct group and fix the RHEL7 User Not In Sudoers File Error.

  1. Start by opening a command line terminal and logging into the root user account.
    $ su -i
    
  2. Then, add your user to the wheel or sudo group, depending on which distro you are running. In this example, we will add our user linuxconfig to the groups, but substitute your own user name into the lines below.RPM based distros:
    # usermod -aG wheel linuxconfig
    

    DEB based distros:

    # usermod -aG sudo linuxconfig
    
  3. To make the changes take effect, you will need to completely log out and log back in. Alternatively, you can just restart the system completely.
    # reboot
    
  4. When you log back into your system, you will be able to execute commands with root privileges by simply prefacing them with sudo. Run some command to make sure it works.
    $ sudo -i
    


Closing Thoughts

In this tutorial, we saw how to fix the user is not in the sudoers file error on RHEL7 and other RPM and DEB based Linux systems. Enabling sudo usage for a user is the recommneded method to running commands with escalated privileges, rather than logging into the root account. This is done both for security and convenience. After all, who wants to login to the root account every time they need to do some administration task?