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
- 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.
- Switch user to root using the su command:
- 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>
- Log out and log in (or reboot) the system for the changes to take effect.
- Check if your user is part of the wheel group by executing in the terminal the command:
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.
- First, switch user to root using the su command. Type your root password when prompted.
- Edit the sudoers file using the vi editor or any other editor you are comfortable with.
- 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.
- 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!