Fixing “username is not in the sudoers file. This incident will be reported” Error In Ubuntu

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.

ubuntu-grub-screen

2. On the next screen, select “Check all file system (will exit read only mode)”.

ubuntu-select-fsck

When you see the message “Finished, press Enter“, press Enter.

3. Next, select “Drop to root shell prompt”.

ubuntu-select-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

5. exit the shell prompt and resume normal boot.

You should be able to perform administrative task again.

Do you like what you read here?

Receive the latest update in your inbox.

33 Comments

  • Andyvan

    (Note: I’m not at home, so can’t check this myself)

    Please verify the instructions above.  In particular, using ‘sudo’ when that’s what you’re trying to fix, and also there seems to be extra text in the example source.  I’m referring to the ”
    is not in the sudoers file. This incident will be reported.” that showsup on a line by itself.

    Reply

    • Damien Oh

      If the user don’t dabble too much with the terminal, chances are he/she won’t ever need this. But if you have got yourself into a mess, the above instruction will be very very useful.

      Reply

      • Anonymous

        But hopefully, Ubuntu users do, indeed, dabble with the terminal – otherwise they might as well use the «legacy OS» !…

        Henri

        Reply

  • Roy

    After installing the gui interface on my Linux server, my username was not in the sudoers file.
    After these steps Linux works great.
    Thanks
    Roy

    Reply

  • Anonymous420115

    Thank you so much! I don’t know how I messed mine up but this was the easiest way to do it.

    Reply

  • TANWTS

    some idiot post the usermod command without specifying that you need the -a option to remain in the sudo (or admin) group. Like it’s a thing of no importance. Many thanks to you for I have fixed the issue.

    Reply

  • Anon

    Hah, I did the same mistake as you: forgot to type -a

    Later I found my original groups off a fresh install of the same distro in KVM but noticed I couldn’t use usermod to update again because I wasn’t in sudo.

    Simple solution, thanks.

    Reply

  • Kanag

    Thank you so much for the post. I too accidentally removed myself from the sudo group as you have mentioned. Using this i solved my problem.\

    Reply

  • Santi

    Thanks for sharing your experience. It solved my problem which was the same as yours. However, I’d like to introduce a little modification I was constrained to do because I was not able to boot in recovery mode – my screen became blank in that mode (and btw the grub menu only appeared by repeatedly pressing the shift key) – What I did instead was to boot from the OS disk – live CD if you like to call it this way – then ‘ctrl+alt+f1′ to gain access to terminal, ‘sudo mount /dev/sda1 /mnt’ in order to mount your system in the hd and ‘sudo chroot /mnt’ to change root directory to current path. Now is time to issue your ‘usermod -a -G … ‘ command. Thanks again.

    Reply

  • Iain

    Thanks for the guide. Was really helpful but initially did not work for me as an error appeard stating there was no admin group. After a bit of reading it seems that the admin group has been replaced with the sudo group in ubuntu 12.04

    Not sure if that has been mentioned as I didnt read all the comments but wanted to share this.

    Thanks

    Reply

  • Onsakia

    Thanks so much for this. It perfectly sorted by problem.

    Much appreciated. As noted by someone above, for Ubuntu 12 just issue the command:

    usermod -a -G sudo [username]

    Great work.

    Reply

  • Johannes Pellenz

    Thanks for the hint.

    In case you have some NAS drives mounted automatically through your fstab, the above mentioned method to mount the drives read-write might fail. Instead, you can do the following (tested on Ubuntu 12.04):

    1. Skip the fschk step, and drop to the root shell immediately
    2. Execute the following commands:
    mount -o remount,rw /
    usermod -a -G sudo [username]
    exit

    Johannes

    Reply

    • Damien

      That might be the method for ArchLinux, but it won’t work in Ubuntu. Ubuntu doesn’t come with a root password by default and you will need root permission to set the password. If you are not in the sudoers file, you can’t carry out any admin role at all.

      Reply

  • Marchi

    fsck must be run, unlocks passwd, FYI Ubuntu 12.04 appears to have no admin group use the following instead,

    sudo adduser sudo

    Reply

  • Jake

    There’s no need to boot in recovery mode.
    Just type

    su -
    [enter password for root]

    Then you can add yourself to the sudo group (i didn’t have an admin group)

    usermod -a -G sudo damien

    Then I still needed to reboot before it had effect :-p

    Reply

    • Damien

      That is provided you have set a password for root previously. Ubuntu doesn’t come with a root password by default, so you can’t use “su” unless you have set a root password previously.

      Reply