Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.
share|improve this question
Well, obviously user not(is) the sudoers file. (Typo in title) – Hello71 Aug 25 '10 at 22:29
You're on the naughty list now - – Aaron Newton Jul 25 '12 at 22:34
up vote 17 down vote accepted

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.

share|improve this answer
I am the admin, since this is my machine and I have installed this system, but it doesn't help :( – Sergiy Byelozyorov Mar 15 '10 at 23:13
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. – Hamish Downer Mar 15 '10 at 23:19
Indeed. My fault. I have forgotten that I have entered the password during the installation back then. – Sergiy Byelozyorov Jan 21 '12 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.

share|improve this answer
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. – Sergiy Byelozyorov Mar 15 '10 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 '10 at 23:32

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.

share|improve this answer

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

echo 'amarzaya ALL=(ALL) ALL' >> /etc/sudoers
share|improve this answer
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 '10 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
share|improve this answer
That's what I was looking for. For me the cleanest as well, no messing with the sudoers file. – webjunkie Aug 29 '12 at 12:57
The correct command is usermod -g oracle admin – kvanberendonck Jan 4 '14 at 7:41
-1: the syntax is usermod -g $group $user. You're probably thinking of the adduser syntax, which is adduser $user $group. – Blacklight Shining Feb 5 '14 at 16:05
…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 – Blacklight Shining Feb 5 '14 at 16:07
@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". – Alain Pannetier Feb 5 '14 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.

share|improve this answer
-1: see pkaeding's comment. – Blacklight Shining Feb 6 '14 at 15:31

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
share|improve this answer
-1: This only works in some local environments that actually have a GUI. – Blacklight Shining Feb 6 '14 at 15:20

Sign in using the following first:

$ su

Then go ahead with:

$ sudo apt-get update

or whatever as normal

share|improve this answer
you don't need su - sudo does this. – Simon Sheehan Dec 2 '11 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. – Aaron Newton Jul 25 '12 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. – Blacklight Shining Feb 6 '14 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. – Blacklight Shining Feb 6 '14 at 15:23

You must log in to answer this question.

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