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 I am 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.
amarzaya@linux-debian-gnu:/$ 
link|improve this question

6  
Incident reported, the police will come for you... – BloodPhilia Aug 25 '10 at 21:47
1  
Well, obviously user not(is) the sudoers file. (Typo in title) – Hello71 Aug 25 '10 at 22:29
2  
Sudo Stop right there, criminal! – Incognito Aug 27 '10 at 14:09
Wow! Never expected this question to be so popular. It has just earned me a golden badge as a famous question :) – Sergiy Byelozyorov Dec 5 '11 at 0:37
feedback

5 Answers

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

link|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
8  
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 at 21:11
feedback

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.

link|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
feedback

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

echo 'amarzaya ALL=(ALL) ALL' >> /etc/sudoers
link|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
feedback

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 oracle to the admin group:

usermod -g admin oracle
link|improve this answer
feedback

Sign in using the following first:

$ su

Then go ahead with:

$ sudo apt-get update

or whatever as normal

link|improve this answer
you don't need su - sudo does this. – Simon Sheehan Dec 2 '11 at 21:01
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.