By default, in Ubuntu, the first user account you created during the installation process is also the administrator of the system. Using this user account, he/she is able to perform administrative tasks with the “sudo” command. If you are not aware, “sudo” refers to Super User Do and all users in this group are geared with administrative rights to manage the system. However, if you accidentally removed yourself from this “sudo” group, you will not be able to do anything. Instead, the only thing you will see is:
damien is not in the sudoers file. This incident will be reported
How I removed myself from the sudo group
For my case, while adding myself to another group, I used the command
usermod -G nogroup damien
without using the ‘
-a‘ parameter and this cause myself to be removed from the sudo group. While I still can use the computer (as a standard user), I am no longer able to update the system, nor install/remove applications.
If you are in the same situation like me, here’s the fix:
1. Reboot the computer. If Ubuntu is your primary and the only operating system in your computer, press the “Shift” button when it is booting up. This should make the Grub screen show up on your monitor. On the Grub screen, press the down button to the Recovery mode and press Enter.
2. On the next screen, select “Check all file system (will exit read only mode)”.
When you see the message “Finished, press Enter“, press Enter.
3. Next, select “Drop to root shell prompt”.
4. You will now be at the command line. Type:
usermod -a -G admin username
Replace the username with your own login name.
5. That’s it. Now type “
exit” and select “Resume normal boot”.
Follow these steps only if you have messed up the /etc/sudoers file
The above steps assume that your /etc/sudoers file is still intact. If you have mishandled the /etc/sudoers file and cause it to be corrupted. Here is what you need to do:
1. Do the above steps until Step 3.
2. At the command line, type
sudo cp /etc/sudoers /etc/sudoers.backup sudo nano /etc/sudoers
Enter the following lines to the file
# # 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 # 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 #includedir /etc/sudoers.d
Press “Ctrl + o” to save the file and “Ctrl + x” to exit.
3. Next, set the file permission of the sudoers file:
chmod 440 /etc/sudoers
4. Lastly, add yourself to the sudo group:
usermod -a -G admin damien
exit the shell prompt and resume normal boot.
You should be able to perform administrative task again.
Our latest tutorials delivered straight to your inbox