I need to install a package. For that I need root access. However the system says that I am not in sudoers file. When trying to edit one, it complains alike! How am I supposed to add myself to the sudoers file if I don't have the right to edit one?

I have installed this system and only administrator. What can I do?

Edit: I have tried visudo already. It requires me to be in sudoers in the first place.

amarzaya@linux-debian-gnu:/$ sudo /usr/sbin/visudo 

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for amarzaya: 
amarzaya is not in the sudoers file.  This incident will be reported.
  • 4
    Well, obviously user not(is) the sudoers file. (Typo in title)
    – Hello71
    Aug 25, 2010 at 22:29
  • 9
    You're on the naughty list now - xkcd.com/838 Jul 25, 2012 at 22:34

9 Answers 9


It would be something of a security hole if you could add yourself to /etc/sudoers without having sudo or root access. Basically then anyone could make themselves root.

Basically you need to ask the administrators of that machine to add you, or to install the package for you, as per the policies of the site.

You should also be sure to use visudo to edit the sudoers file - it checks that the syntax is correct before writing the file. And you can use editors other than vi with visudo. It will by default use whatever you have set as $EDITOR and if you don't have it set you could do

# EDITOR=nano visudo

to use the nano editor instead.

  • 5
    I am the admin, since this is my machine and I have installed this system, but it doesn't help :( Mar 15, 2010 at 23:13
  • 9
    If it is your system then you should have entered a password for the root user when installing. So login as 'root' and then do the visudo stuff. Mar 15, 2010 at 23:19
  • Indeed. My fault. I have forgotten that I have entered the password during the installation back then. Jan 21, 2012 at 21:11

Login as root and use /usr/sbin/visudo to edit the file and add your username. Normal vi/vim will not be able to edit the file.

The easiest way is to just go down until you see the line "root ALL=(ALL) ALL" and add yourself under that with the same syntax (yourusername ALL=(ALL) ALL). Or, you can read the sudoers manpage if you want to give yourself more specific privileges.

  • It requires me to be in sudoers list in the first place in order to run visudo. I have installed this Debian, there no other admin. Mar 15, 2010 at 23:12
  • If you are logged in as root, you don't need to run sudo visudo; just run /usr/sbin/visudo. But it looks like you already found this out, from the other answer's comments.
    – Ricket
    Mar 15, 2010 at 23:32
  • isn't enough to add the respective user to the "sudo" or "sudoers" (depending on the distro) group? Sadly in my case, it didn't work, but I could swear this used to work...?
    – Gregor
    Nov 10, 2016 at 22:27

Just typed the command:

$ su

And asked for the password "root". Typed and boom... It worked!

This problem was my mistake. Due to be back at the facility at the time I created the username and password.

  • Thanks that was really helpful and saved my bacon! But i'm curious why simply adding this command and then the root password, would allow elevated privileges.... seems to rather defeat the purpose of the message "User not in the sudoers file. This incident will be reported" Dec 2, 2016 at 5:17

Perhaps the easiest way, once you're root, is:

echo 'amarzaya ALL=(ALL) ALL' >> /etc/sudoers
  • 8
    You should be sure to use visudo to edit the sudoers file, rather than edit it directly or echo text to it. This will ensure that it is syntactically correct, and ensure that you don't lock yourself out of access, or grant someone improper access.
    – pkaeding
    Jun 15, 2010 at 3:51

If your sudoers file already contains this kind of line

# Members of the admin group may gain root privileges
%admin ALL=(ALL) ALL

Then, the cleanest way of doing things is probably to grant the admin group to your user. For instance, to add user oracle to the admin group:

usermod -aG admin oracle
  • That's what I was looking for. For me the cleanest as well, no messing with the sudoers file.
    – webjunkie
    Aug 29, 2012 at 12:57
  • 1
    The correct command is usermod -g oracle admin
    – kvanbere
    Jan 4, 2014 at 7:41
  • -1: the syntax is usermod -g $group $user. You're probably thinking of the adduser syntax, which is adduser $user $group. Feb 5, 2014 at 16:05
  • 1
    …actually, you'll most likely want usermod -aG $group $user. -g sets the user's primary group to the one you specify, and -G without -a will remove the user from groups that are not listed. -g will also change the group ownership of all files owned by the previous group in the user's home directory. So if you're like me and you have your umask set to 007 Feb 5, 2014 at 16:07
  • 1
    @BlacklightShining. You're right. The wrong syntax was proposed by a previous commenter and since oracle is often a group as well, there is indeed room for confusion. I shouldn't have "corrected". Feb 5, 2014 at 20:51

In case you can still get root access using su, you can use this one-liner to add yourself to /etc/sudoers/:

su -c 'echo $USER ALL=(ALL)ALL >> /etc/sudoers'

To activate the change, log out and in again. For example end your the X Session or log out via shell enter exit.


If you cannot use the sudo command, then you can use the following method:

  1. Press Ctrl+Alt+F1
  2. Log the user out if the user is not root
  3. Log in as root
  4. Use root privileges
  5. Log out (exit) – Ctrl+Alt+F7 to get to the GUI
  • -1: This only works in some local environments that actually have a GUI. Feb 6, 2014 at 15:20

All you need is add your <username> to whell group.

# usermod -aG whell username

Then login with your username and enjoy :)


Sign in using the following first:

$ su

Then go ahead with:

$ sudo apt-get update

or whatever as normal

  • 1
    you don't need su - sudo does this. Dec 2, 2011 at 21:01
  • They are not quite the same thing actually. sudo is 'do as super user', but you login with your user's password. su is 'switch user', and by default (without arguments) it attempts to switch to the root user, in which case you need to enter the root password. But you are also correct - using sudo after su is redundant, since you would already be the root user. Jul 25, 2012 at 22:39
  • @aaron.newton I would actually read it as Switch User and DO; you can pick any user to run the command as with the -u flag. It is mostly used for root, but so is su. Feb 6, 2014 at 15:23
  • @aaron.newton I would actually read it as Switch User and DO; you can pick any user to run the command as with the -u flag. It is mostly used for root, but so is su. Feb 6, 2014 at 15:23

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .