question : I want to use sudo on my Linux system to run some privileged commands, but when I try to do this, I get the "[my username] is isn't in the sudoers file. This incident would be reported. " Error message. What should I do with this sudo error?
sudo is a privilege that allows specific groups of users to run a command with the privileges of another user (typically root). Sudo has detailed logging capabilities and provides fine-grained control over which commands the user can run with sudo.
Sudo vs. Su
The SU command also provides the same elevation of privilege, unlike the granularity of their authentication process and the change in privilege. SU allows you to switch from your login session to another user's session, and then you can run any program with the user's privileges, but you need to know the target user's password to switch the user. sudo, on the other hand, can work on a single command, allowing you to run individual commands with the privileges of root. With sudo you do not have to know the root password, but enter your password when prompted to enter the sudo password.
Adding users to the Sudoers list
As a new user you will encounter the following error if you try to run the sudo command. It means you're not in this list of sudoers that contains a user group that has been certified to use sudo privileges.
- [My-user-id] is isn't in the sudoers file. This incident would be reported.
There are two ways to add you to the Sudoers list.
Method One
The first method is to add you to the Linux user group named sudo. This particular Linux user group is preconfigured to use sudo. So once you're inside this group, you can run the sudo command.
The following command will add you to the sudo group in Linux and you will need to run the command under the root user.
- # AddUser < username > sudo
Now to confirm that your membership has been updated, use the groups command to see the list of groups you currently belong to. This list must contain the sudo group.
- $ Groups
- Alice ADM cdrom sudo dip plugdev fuse lpadmin netdev sambashare davfs2 libvirtd Docker promiscuous
Changes to the membership (and sudo access) will take effect after you log out and re-login.
Method Two
The second way to get you to use sudo is to add yourself directly to the/etc/sudoers configuration file.
To modify the/etc/sudoers file, you can use a special sudo editor command called Visudo. Simply invoke the following command as root.
- # Visudo
This command can open and edit the/etc/sudoers file, add the following line of text to the end of the file, and press ctrl+x. When the prompt appears, save the changes to exit.
- <username> all= (All) all
This change will take effect immediately and you'll be able to use sudo right away.
Linux Ask a question: How to solve "XXX is not in the sudoers file" error