How to fix "user is not in the sudoers file" error on your Linux Server?






Need to solve "user is not in the sudoers file" error? This guide will help you through.


Most Webmasters lose privileges to use the sudo command thereby getting an error such as "user is not in the sudoers file".


Here at Ibmi Media, as part of our Server Management Services, we regularly help our customers to fix Linux User permissions issue.


Now, let us look into how to fix this error.


What triggers "user is not in the sudoers file" error?

The Sudoers file "/etc/sudoers" determines who can run what commands as what users on what machines and can also control special things such as whether you need a password for particular commands. The file is composed of aliases (basically variables) and user specifications (which control who can run what).


It is usually caused by any of the following reasons;


i. When the permission on the "/etc/sudoers" file is not set to 0440.

ii. In cases where a user is taken off the sudo or admin group.

iii. The "/etc/sudoers" file was modified to restrict users in sudo from using their privileges using the sudo command.


Steps to fix "user is not in the sudoers file" error?

To fix this error, you can simply add the affected user to the Wheel group. This can be performed by any user with superuser (su) access.


The wheel group is a specialized user group in Linux which can be implemented on your Machine. It controls access to the sudo command which permits a user to behave as a superuser.


Then, Once the user is added to the group, access to the the sudo command will be granted.


How to add user to Sudoers File?

With a superuser account, log into your Server via an SSH tool. Then run the command below to add the username to the Wheel group;


#Add your user to the Wheel group.
#Change bob to your user name.
usermod -G wheel ibmimedia


Then with the exit command, you can exist the superuser account.


This will allow the user "ibmimedia" to perform tasks will sudo privileges.


How to grant sudo Privileges to Users?

Sometimes when the "/etc/sudoers" file is modified to restrict users in sudo or admin group  from using their privileges' as a superuser, then this will trigger this error.

To fix this, first make a backup of the sudoers file by running the command below;


cp /etc/sudoers /etc/sudoers.backups


Then edit the sudoers file and add the contents as shown 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


How to set the right permissions for the sudoers File?

The permission for the "/etc/sudoers" file must be set to 0440 by running the command below;


chmod 0440 /etc/sudoers


This will allow you access to perform any task as specified by the sudo functionality and command.


Need support in fixing "user is not in the sudoers file" error? We are available to help you today.


Conclusion

Basically, when the wrong permission is assigned to the sudoers file, the error "user is not in the sudoers file" is usually triggered.



Related Post


Keep In Touch

We hope to hear from you.

Accept File Type: jpg,jpeg,png,txt,pdf,doc,docx