In this article, we will fix a common error that new Linux users encounter
username is not in sudoers file. The problem is related to user permissions and can be simply resolved with a single command.
If you have recently established a new user on your Linux distribution, you may see the error “
username is not in soders file” when using
If you’re in a rush and need to fix the issue without knowing the context of the error, here’s how. Please use any of the following methods to grant user
sudo access, depending on the Linux distribution you’re using.
Add user to sudoers file or sudo group
For Ubuntu or its derivatives
sudo usermod -aG sudo username
For CentOS or other RHEL’s derivatives
sudo privileges in CentOS and other Red Hat Enterprise Linux derivatives, the user must be assigned to the
wheel group –
sudo usermod -aG wheel username
sudo privileges to a user, you can directly modify the
sudoers file and add the following line. This method is equally applicable to any other Linux distribution.
Add the following line at the end of the file –
username ALL=(ALL) NOPASSWD:ALL
For Arch Linux and derivatives –
sudo is most likely not pre-installed with the default system. To begin, install
pacman -S sudo
Now, add the user to the
wheel group and grant it
usermod -aG wheel username
An extra step Arch necessitates is granting
sudo access to users from all wheel group, which we accomplish by changing the sudoers file. So, using
visudo, open the sudoers file.
Now find and uncomment the line “#
%wheel ALL=(ALL) ALL". Just remove the # to uncomment it.
## Uncomment to allow members of group wheel to execute any command %wheel ALL=(ALL) ALL
sudo. If you’re still reading, you’re probably asking why my specific Linux distribution doesn’t address the problem. The solution, of course, is in the context, which I avoided explaining above. But now it’s here.
sudo access is not granted by default to newly created users. It’s for your own safety. Yes, you guessed correctly.
can be used by a less trusted or untrusted user to edit system files. Only trusted users should be in the sudoers file or the
sudo and wheel group since
sudo is a powerful command.
What is visudo?
The sudoers file can be found at
visudo command is a tiny utility for editing the sudoers file. Although we can change the sudoers file directly, it is highly advised that we use
visudo. Before saving the file, visudo will examine the syntax of each line. If we save the sudoers file with the incorrect syntax, we may lose all
sudo access. If there are mistakes,
visudo will not allow anyone to save the file.
So that’s how to fix “username is not in sudoers file” error. We add the user to the
sudo group or change the
sudo file, and that’s about it. Finally, before concluding the post, I wanted to add a minor piece of information. Any user in any group can be added using the