Fix user is not in the sudoers file in Linux

By Leonard Cucos •  Updated: 11/16/21 •  3 min read

This is a quick guide on how to fix the “user is not in the sudoers file” in Linux/UNIX. The issue is caused by your user not having sudo access in your system and can be quickly fixed by adding the user to the wheel group using the usermod command or via editing the sudoers file in your Linux system.

I recently encountered the “user is not in the sudoers file” error when attempting to install NVIDIA drivers in Fedora Silverblue using the sudo command. In Fedora Silverblue you can choose during the installer if you want to grant a user administrative privileges and I probably left this option unchecked.

In this guide, I am going to show you two quick methods to fix the “user is not in the sudoers file” issue to give your user access to sudo. I am going to use Fedora Silverblue but the same procedure should work on any other Linux distribution out there.

Method 1: Using the usermod command

  1. First, find what is your user name by opening a terminal and executing the command below. Skip this step if you already know your user name.
whoami
  1. Switch user to root using the su command:
su -
  1. Add your user to the wheel group by executing the following command. Replacing the <username> with the user name in step 1 above. 
sudo usermod -aG wheel <username>
  1. Log out and log in (or reboot) the system for the changes to take effect.
  2. Check if your user is part of the wheel group by executing in the terminal the command:
groups

Now your user should execute commands that require elevation, with sudo in Linux without issues.

Method 2: Using the sudoers file

This method will fix the “user is not in the sudoers file” by editing the /etc/sudoers file. 

  1. First, switch user to root using the su command. Type your root password when prompted.
su -
  1. Edit the sudoers file using the vi editor or any other editor you are comfortable with. 
visudo
  1. Scroll down until you find root  ALL=(ALL)  ALL and add the following line below it. Replace <username> with your actual user name.
<your username> ALL=(ALL) ALL

Here is how your sudoers file should look like. The new line is underlined in red.

Save and exit the file.

  1. Log out and back in (or reboot) the system for the change to take effect.

You should be able now to run commands with sudo in Linux/UNIX without any issues. This guide was tested on a few other Linux distributions (Debian, Ubuntu, Arch) as well as in UNIX (FreeBSD).

That’s it. This is how you fix the “user is not in the sudoers file” error in Linux. I hope you found this post useful. Be well!

Leonard Cucos

Leonard Cucos is an engineer with over 20 years of IT/Telco experience managing large UNIX/Linux-based server infrastructures, IP and Optics core networks, Information Security [red/blue], Data Science, and FinTech.