Webmasters at times lose privileges to use the sudo command which in turn triggers the “User is not in the sudoers file” error.
As a part of our Server Management Services, we help our Customers to fix user permissions regularly.
Let us today discuss the possible causes and fixes for this error.
What causes the “user is not in the sudoers file” error?
Sudoers file determines which all users can run administrative tasks and the tasks that require superuser privileges. It commonly triggers this error when the user is not part of this file.
Any of the following may cause a broken sudo:
- A user removed from the sudo or admin group.
- The /etc/sudoers file was altered to prevent users in sudo or admin group from elevating their privileges to that of root using the sudo command.
- The permission on /etc/sudoers file is not set to 0440.
How to fix “user is not in the sudoers file” error
Adding the impacted user to the Wheel group will help to fix this issue. Any user with superuser (su) access can perform this task.
The wheel group is a special user group on Linux systems. It controls access to the sudo command which allows a user to behave as a superuser.
Once we will add our user to this group, we will be able to use the sudo command.
Adding a Linux user to Sudoers File
First, connect to the Linux server using any superuser account. Then add the username to the Wheel group.
#Add your user to the Wheel group.
#Change bob to your user name.
usermod -G wheel bob
Now exit from the superuser account using the exit command. This should allow the user bob to execute tasks that require administrative privileges.
Granting sudo Privileges to Users
At times this error occurs on altering the /etc/sudoers file to prevent users in sudo or admin group from elevating their privileges to that of a superuser. In such cases, make a backup of the sudoers files as follows:
# cp /etc/sudoers /etc/sudoers.orginal
Subsequently, open the sudoers file using visudo and add the content below:
#
# This file MUST be edited with the 'visudo' command as root.
#
# Please consider adding local content in /etc/sudoers.d/ instead of
# directly modifying this file.
#
# See the man page for details on how to write a sudoers file.
#
Defaults env_reset
Defaults mail_badpass
Defaults secure_path="/usr/local/sbin:/usr/local/bin:/usr/sbi$
# Host alias specification
# User alias specification
# Cmnd alias specification
# User privilege specification
root ALL=(ALL:ALL) ALL
# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL
# Allow members of group sudo to execute any command
%sudo ALL=(ALL:ALL) ALL
# See sudoers(5) for more information on "#include" directives:
#includedir /etc/sudoers.d
Setting Correct Permission on sudoers File
If the permission on /etc/sudoers file is not set to 0440, then run the following command to make it right:
# chmod 0440 /etc/sudoers
Now we have access to run anything using the sudo command. Our username is part of the sudoers file so you can perform your activities using the sudo command now.
[Need any further assistance to fix the user is not in the sudoers file error? – We’re available 24*7]
Conclusion
In short, the user is not in the sudoers file error triggers due to the wrong permission of the sudoers file or when the user is removed from it. Today, we saw how our Support Engineers fix this error.
0 Comments