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

For my case, while adding myself to another group, I used the command

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:

Replace the username with your own login name.

5. That’s it. Now type “exit” and select “Resume normal boot”.

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

Enter the following lines to the file

Press “Ctrl + o” to save the file and “Ctrl + x” to exit.

3. Next, set the file permission of the sudoers file:

4. Lastly, add yourself to the sudo group:

5. exit the shell prompt and resume normal boot.

You should be able to perform administrative task again.

32 comments

  1. (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.

  2. Very valuable information, Damien, which I hope most users will never have to employ. Thanks !…

    Henri

    • 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.

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

        Henri

  3. 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

  4. You could avoid this fail if you just set a root password after install with: sudo passwd

  5. 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.

  6. 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.

  7. 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.\

  8. 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.

  9. 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

  10. 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.

  11. Thank you very much – this has helped me a lot. Another thing learnt about Ubuntu today for me!

    Regards,
    Anton

  12. 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

    • 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.

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

    sudo adduser sudo

  14. 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

    • 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.

Comments are closed.

Sponsored Stories