My main username is not in the sudoers file

127,528

Solution 1

Open a Root Terminal and type visudo (to access and edit the list).

Navigate to the bottom of the sudoers file that is now displayed in the terminal.

Just under the line that looks like the following:

    root ALL=(ALL) ALL

Add the following (replacing user with your actual username):

    user ALL=(ALL) ALL

Now save the file. The procedure for this will depend on your editor:

  • nanoCtrlO then Enter, then CtrlX to exit
  • vim:wq

Solution 2

The simplest way to add an user to sudoers file is run the command bellow as user with permission to execute gpasswd:

sudo gpasswd -a username sudo

Solution 3

the process described at search: "psychocats ubuntu fixsudo" helped me on Lubuntu 13.04

Enter recovery mode then

mount -o rw,remount /

adduser username sudo
Share:
127,528

Related videos on Youtube

Braiam
Author by

Braiam

Updated on September 18, 2022

Comments

  • Braiam
    Braiam over 1 year

    I was trying to install some software/edit files with my main username(not root) But I got this error [X] is not in the sudoers file. This incident will be reported.
    I tried to edit the /etc/sudoers file by using sudo and su username but I got the same error!

    How I'm supposed to add my username tosudoers file while I cant access it anyway?
    I also tried to follow this guide here.

    is the guide says, when booting 2 Operating systems(that's my case), then selecting Ubuntu, a menu will let you choose to start normally/open recovery mode/etc, but it's not happening for me, even if I hold shift no menu will pop up.

    I installed Ubuntu by using Wubi and my Ubuntu version:12.04 LTS.

    • Admin
      Admin about 12 years
      That guide looks pretty good for dealing with your sudo problem, and would probably work if you could follow it. I think you need to change your question to be "How can I boot into recovery mode?" and then ask about sudo if following that guide does not fix the problem.
    • Admin
      Admin about 12 years
      To boot into recovery mode, restart the PC and hold down the Shift button, then follow the instructions - psychocats.net/ubuntu/fixsudo
    • Admin
      Admin about 12 years
      you will not get the Grub menu for a wubi install. If you have any other user account you can access, which has permissions to edit sudoers file, that may help. Else, you may have to use external tools for that. It certainly can be solved. :)
  • Mahesh
    Mahesh about 12 years
    His problem is in accessing a root terminal. And, you assumed that his editor is nano. Kindly improve it.
  • Anwar
    Anwar about 12 years
    How can he open a Root Terminal without giving root password which is not working?
  • jasmines
    jasmines about 12 years
    You can easily find some online tutorial to retrieve/change your root password and you'll be able to open a standard terminal and give su to become root. Otherwise, you may want to boot with a Live CD and access the file after having mounted the HD. Finally, I wasn't referring to nano. visudo is included in standard Ubuntu installation.
  • Fredrick Gauss
    Fredrick Gauss about 10 years
    Ctrl + K then X worked.
  • Andy K
    Andy K over 8 years
    Many thanks @monteirobrena. Your tip is very useful :)))
  • jmng
    jmng over 6 years
    This is the easiest way I've encountered to solve this problem. For anyone wondering, you need to boot in recovery mode and choose "Drop to root shell prompt" to execute these commands (wiki.ubuntu.com/RecoveryMode)